This script is hacket together to make merging multiple repos into one as easy as possible. It clones each sub-project and then uses git-filter-repo to move each repo into a sub directory. Finally it uses https://github.com/robinst/git-merge-repos for the final merge.
In other words, it takes this:
| project-1 (separate repo)
| - dir-1
| - file-1.txt
| - README.md
| project-2 (separate repo)
| - dir-2
| - file-2.txt
| project-3 (separate repo)
| - dir-3
| - file-3.txt
and turn it into this:
| new-repo
| - project-1
| - dir-1
| - file-1.txt
| - README.md
| - project-2
| - dir-2
| - file-2.txt
| - project-3
| - dir-3
| - file-3.txt
With all history of each project retained.
This script requires Groovy 2.5.x. You can obtain that by using SDKman (see https://sdkman.io)
To get Groovy on your classpath use this command:
sdk install groovy 2.5.614
If you do not have Java on your classpath you can use SDKman to install that too:
sdk install java 11.0.11-open
Now download merge-git.groovy
below and make it executable (this is for posix compatible systems only)
Create a repos.txt
file with content like the example below. I use the git@_
notation. I don't know if my script works with https://
Now execute
./merge-git repos.txt
The script will create a ./tmp
directory in the current directory and make a script inside it called merge.sh
You can change the directory by adding -d myDir
and the script name by adding -s myScripg.sh
like this
./merge-git repos.txt -d myDir -s myScript.sh repos.sh
The generated script is not executed, but waiting for you to run it. Please review it before executing.
Note: That the script does not push anything back to the original repos. Also note that the merged repos can be found in ./tmp/merged-repo
(or your custom directory). This repo does not have a remote, so you need to add that yourself with git remote
Enjoy. If you use this script, please write a comment below.
YOU ARE FREE TO USE AND MODIFY THIS SCRIPT. IT COMES WITH NO WARANTY OR GUARANTEES WHAT SO EVER. I TAKE NO RESPONSIBILITY IF YOU USE THIS.