Just recently I needed to merge multiple Git repositories into one. This might seem trivial, but there are just so many ways to do this, it can be confusing 🙂
My requirements were:
- merge multiple repositories into a new repository
- preserve history of all artefacts
- have every old repository in its own folder in the new repository
- migrate all existing issues
I intended to delete the „old“ repositories after successful migration.
Let’s make the following assumptions:
- your Github username: johndoe
- your old repository: jdapp
- your new repository: jdshinynewapp
Step 1: Create new repository
Too trivial to describe here 🙂 Just create the repo and clone to your local disk. Then „cd“ into the „jdshinynewapp“ directory.
Step 2: Merge old repository into new
git remote add jdapp https://github.com/johndoe/jdapp.git git fetch jdapp git merge jdapp/master
Step 3: Move merged old repository to subfolder
Now just create a new folder in your jdshinynewapp directory, move the contents of your old repository there and do a commit followed by a push.
Step 4: Remove old remote repository
git remote rm jdapp
Step 5: Migrate issues
There are quite a few scripts utilizing the Github APIs to migrate issues. Also, Github now has a „beta“ feature for migrating issues. I tend to trust Github the most, so decided to use this, even if it doesn’t support bulk operations. I had to migrate ~160 issues, which was still manageable for me, doing it one by one.
To transfer an issue, open it and use the „Transfer this issue“ link on the bottom right of the issue details. Note that – at least for me – it did not migrate labels, milestones, project information, even if the new repository had corresponding data (e.g. same milestones).
Step 6: Repeat
Repeat steps 2 through 5 for any other old repositories you’d like to migrate.