Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Migrate one git repository into another (e.g. migration into a monorepo)
# To merge project-a into project-b:
cd path/to/cloned-project-b
git checkout -b my-migration-branch
git remote add -f project-a git@github.com:user/project-a
# Replace `master` below with the branch you wish to migrate but it should be your primary working branch
git merge --allow-unrelated-histories -s ours --no-commit project-a/master
# ALWAYS end the prefix path with the slash
git read-tree --prefix=path/relative/to/cloned-project-b/ -u project-a/master
git commit -m "merge"
git pull -s subtree project-a master
# DO NOT SQUASH MERGE TO MASTER OR ALL OF THIS HISTORY PRESERVATION WILL BE MOOT!
# If more commits are added to project-a/master you can pull those in:
git pull -s subtree project-a master
# For users that haven't run the above commands from the beginning, they
# can:
cd path/to/cloned-project-b
git checkout -b my-migration-branch
git remote add -f project-a path/to/project-a
git subtree pull --prefix=path/relative/to/cloned-project-b/ project-a master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.