I have two git repositories and I want to merge them together without losing their commit histories. I've tried this:
cd firstRepo git remote add other path/to/otherRepo git fetch other git checkout -b otherRepoBranch other/master echo "`git rev-list otherRepoBranch | tail -n 1` `git rev-list master | head -n 1`" >> .git/info/grafts git rebase otherRepoBranch master
Now when I look at the commit history everything looks good, but the only files I have in my repository are now the ones from otherRepo.
Any ideas?
I take it the git repositories are unrelated? As in they're distinct repositories for separate projects that you want to be merged together to form a combined repository? If so, then it's possible the following references may help:
Combining multiple git repositories.
Merging two unrelated repositories.
This definitive article addresses the simple case in the opening paragraph -- and addresses the more likely case as its primary topic: How to use the subtree merge strategy
The commit history of both repositories is preserved.
Here's my version -- based on the above referenced article...
git remote add temp staging_path/(reponame) git fetch temp git fetch --tags temp ## optional -- may pull in additional history for remote in $(git branch -r | grep temp/ ) ; do git branch --no-track imported_$(basename $remote) $remote ; done ## create local branches prefixed with 'imported_' git remote rm temp ## optional -- assumes you no longer plan to use the source repo git merge -s ours --no-commit imported_master ## mysterious "merge strategy" git read-tree -u --prefix=(reponame)/ imported_master ## move to sub-folder git commit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With