Jul 22, 2009

How to merge two independent git repositories

I have two independent repositories (A and B) and would like to merge one repo. (B) into another one (A) with keeping the whole history of both. What do to?
With git it appeared to be a very easy task.

cd A
git remote add test ../B && git fetch test
git merge test/master
git push (if you use a remote repo.)

That's it.

You can also merge a subdir of one repo. into another. But to do so you need to use git filter-branch.

I love git! ;)

11 comments:

masha said...

Thanks, this was exactly what I was looking for.

Dmitry said...

Thank you, was really useful! :)

Anar Manafov said...

you are welcome ;)
Git is awesome!

Anonymous said...

Thank you. I am little new to git and was looking for this feature for one of my projects. Your post was very very helpful.

Anar Manafov said...

;) You are welcome!

Anonymous said...

You just saved me some hours of my life. Thanks.

Anar Manafov said...

;) Thanks for the comment!

Mike Mainguy said...

Awsome, this made my day... I spent 30 minutes reading complicated ways to do this and I had it done this way in 15 minutes...

Good work!

Kaizer said...

Thanks! Your blog lays this out very simply. For folks who want to meld two git repos that involves pruning and grafting, this blog gives a run book-

http://www.simplicidade.org/notes/archives/2009/04/merging_two_unr.html

Gordon Barrs said...

+1 for what me said. Thanks for taking the time to post.

Anonymous said...

you are the man. :)