How to merge two GIT repositories

Published at 02, October 2008, author art. Tags: git, my-projects, vcs

I have a project on GitHub. It's name is django-vcs-watch. Also, I had a test django project in separate directory. This test project was a separate git repository, but today I decided to made it a part of [django-vcs-watch] and include as example project to the main repository at GitHub.

So, I started to search how to merge two git repositories together. And furtunately, I have found the solution. See the comments for this post, where Tobu suggests to use git filter-branch and pulling to get two repositories together.

First, full vcs_test projects content was moved to a new subdirectory example, using this command:

git filter-branch --index-filter 'git ls-files -s | sed "s-\t-&example/-" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD

Next, I'm went to the django-vcs-watch directory, and just make a pull:

git pull ../vcs_watch/

That's it! Just one git push, and all changes will go to the GitHub. Hey! They are already there!

Note, that git-filter-branch has other interesting applications. For example, you can split you repository, or remove some unwanted commits. Anyway, this command is very dangerous, don't try to repeat these experiments at home, or at least, have a backup :-)

Pingbacks

permalink

04, March 2009, pingback from http://www.etlafins.com/archives/702:

Thanks to this blog post I was able to figure out how to do all this without losing any of the development history (without this I likely would not have done it at all). I have also already done the grunt work of merging the files and fixing the the references in the source, so all that is left is to push the changes up to GitHub and

Comments

Subscribe on this post's comments

No comments. Wanna be first?

First, identify yourself and come back to leave comments.

If you wish to leave comment, please, identify yourself and then come back to this page.