Skip to content

Instantly share code, notes, and snippets.

@worldsayshi
Last active December 25, 2015 04:09
Show Gist options
  • Save worldsayshi/6914812 to your computer and use it in GitHub Desktop.
Save worldsayshi/6914812 to your computer and use it in GitHub Desktop.
How to merge git repos into a parent repo while maintaining history and using only "conventional git commands"

How to merge git repos with history with conventional git commands only

Clone what is to become child projects

git clone git:path/to/repo1
git clone git:path/to/repo2

Move repo contents one level down. By default this should not move hidden files. We don't want to move the .git folder so that is good.

mkdir repo1/repo1
mv repo1/* repo1/repo1/
cd repo1
git add -A
git commit -m "For merging with parent repo"
cd ..

mkdir repo2/repo2
mv repo2/* repo2/repo2/
cd repo2
git add -A
git commit -m "For merging with parent repo"
cd ..

Create parent repo

mkdir parent
cd parent
git init

( Alternatively, clone the parent from wherever you keep it )

git clone git:path/to/parent
cd parent

Pull child projects into parent repo

git pull ../repo1
git pull ../repo2

Done! Now all that is left is to push the parent to the appropriate upstream location.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment