Skip to content

Instantly share code, notes, and snippets.

@ixmatus
Created August 14, 2019 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ixmatus/9a8dd88c167aa030196e1f3547f1e86d to your computer and use it in GitHub Desktop.
Save ixmatus/9a8dd88c167aa030196e1f3547f1e86d to your computer and use it in GitHub Desktop.
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