Merging of Git Repositories

If you ever need to merge multiple git repositories into a single repository and also keep the history, then i have just the script for you. This script will keep your branches and tags, but since tags often are called the same, the tags and branches of a repository is renamed so that the original repository name is prefixed.

If you had the following branches and tags in your project “myproject”:

  • master
  • develop
  • feature/my-feature
  • 0.1.0
  • 0.1.1

Then they would become:

  • myproject/master
  • myproject/develop
  • myproject/feature/my-feature
  • myproject/0.1.0
  • myproject/0.1.1

Further if the original repository has more than one file and/or directory in the root, then these get moved in to a sub directory so that we don’t have conflicts with other projects.

To use the project simply create a file with the list of repository URLs you want to merge, e.g.:

# Merge repositories:

Then you can perform the merge using the following script as so:

./ test repos.list

So here is the script: