Last active
December 14, 2015 22:09
-
-
Save dkordik/5156058 to your computer and use it in GitHub Desktop.
An example of merging 3 git repos into 1, and preserving all the history.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#setting the stage... creating 3 separate repos | |
mkdir animals; cd animals/; echo "Animals" > README; git init; git add .; git commit -m "Animals readme"; cd .. | |
mkdir dogs; cd dogs/; echo "Dogs" > README; git init; git add .; git commit -m "Dogs readme"; cd .. | |
mkdir cats; cd cats/; echo "Cats" > README; git init; git add .; git commit -m "Cats readme"; cd .. | |
#putting stuff in boxes for the move... | |
cd cats; mkdir cats #making /cats inside of cats, because in /animals we want /cats to be a subdir | |
git mv README cats #this line needs to me more appropriate to the contents of your actual child repo | |
git commit -m "Prepare cats for merge into animals"; cd .. | |
#the short version, for dogs... | |
cd dogs; mkdir dogs; git mv README dogs; git commit -m "Prepare dogs for merge into animals"; cd .. | |
#time to combine the repos. let git remotes do the work. | |
cd animals; | |
git remote add cats ../cats; git pull cats master; git remote rm cats | |
git remote add dogs ../dogs; git pull dogs master; git remote rm dogs | |
git log | |
#you should see all the history in here. | |
#kill the original dogs and cats at your leisure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment