Git push subdirectory to another main repo

I have a large main project with several directories like subtrees .

I want to push changes in one specific subtree to its beginning, which is a separate repository.

The problem is that the current subtree I want to click on was not originally from the repository I want to paste into. This came from another repo, through the subtree guides that I found on Google. It looks very similar.

A large project outline where important_subtree is what I'm worried about.

 ~/devel/bigproject .git/ some_subtree/ other_subtree/ important_subtree/ abc.txt efg.txt <--- new version hij.txt 

And important_subtree "strongly connected" to this repo:

 ~/devel/important .git/ abc.txt efg.txt <--- old version hij.txt 

Now ~/devel/bigproject/important_subtree/efg.txt has changed, and I want to push important_subtree on the repo ~/devel/important . Therefore afterwards ~/devel/important/efg.txt also change.

The only thing I managed to do was to click on to make everything in a large project important, which is clearly not what I want. Only changes in the subtree should be pushed.

+4
source share
3 answers

This is not so difficult anymore, you can simply use the git filter-branch command on the clone of your repo to drop the subdirectories you don’t want, and then click on the new remote.

 git clone <ORIG_REPO_DIR> <NEW_REPO_DIR> cd <NEW_REPO_DIR> git filter-branch --prune-empty --subdirectory-filter <THE_SUBDIR_TO_MAKE_NEW_ROOTDIR> master git push <MY_NEW_REMOTE_ORIGIN_URL> -f . 
+2
source

I would recommend git-subtree addition to git. He adds the git subtree split , which does what you want.

 git subtree split --prefix=important_subtree --branch=backport <subtree merge SHA1>^.. --onto=<imported SHA1> --rejoin git push ~/devel/important backport:master 

This cherry picks the changes in bigproject , since you merged important as a subtree, using only those that changed important_subtree/ . He then applies them as new commits on top of the commits that you imported from ~/devel/important , and creates a backport branch that you can drop in the usual way. In addition, --rejoin makes it so that you do not need to use commit identifiers in the future if you want to repeat the process with additional changes.

A more detailed description of the author's blog post .

+3
source

Pushing different branches can be a very difficult task.

Perhaps the easiest way:

  • Clone your “important” repo from the server again.
  • In your "large projects" create patches that contain exactly the changes that you intended (for example, git format-patch) (you may need to first make "smaller" commits in the side branch if your original compiles the mixing files that you need to click , and such files that should not)
  • In your new "important" clone, apply patches (git am)
  • Click the new clone "Important" on its default remote wizard. Now the push is simply forward and should not cause problems.
+1
source

All Articles