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:
git@github.com:4treesCH/strolch-wc-inspector.git
git@github.com:4treesCH/strolch-wc-auth.git
git@github.com:4treesCH/strolch-wc-localize-behavior.git
git@github.com:4treesCH/strolchjs.git
git@github.com:4treesCH/strolch-wc-styles.git
git@github.com:4treesCH/strolch.git

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

./mergeGitRepositories.sh test repos.list

So here is the script:

https://paste.ubuntu.com/p/BhKvmMnqFQ/