Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git push a sub-directory into another main repo

I have a big main project with several directories as subtrees.

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

The trouble seems to be, that the current subtree I want to push does not originally came from the repository I want to push into. It came from a different repo, via the subtree guides I found by googling. It just looks very similar.

Big project layout, where important_subtree is the thing I am worried about.

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

And the important_subtree is "strongly related" to that 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 the important_subtree onto the repo ~/devel/important. So afterwards ~/devel/important/efg.txt also has the changes.

The only thing I managed to do is to push push everything in bigproject into important, which is obviously not what I want. Only the changes in the subtree should be pushed.

like image 986
towi Avatar asked Aug 10 '11 12:08

towi


1 Answers

This is no longer so complex, you can just use the git filter-branch command on a clone of your repo to cull the subdirectories you don't want and then push to 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 .
like image 102
jeremyjjbrown Avatar answered Oct 27 '22 10:10

jeremyjjbrown