Skip to content

Instantly share code, notes, and snippets.

@berstend
Created March 5, 2019 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berstend/7d55d2f8232fa1c34fb797485ffb667e to your computer and use it in GitHub Desktop.
Save berstend/7d55d2f8232fa1c34fb797485ffb667e to your computer and use it in GitHub Desktop.
Make a monorepo with existing repos
#!/usr/bin/env bash
# Before:
# (Assuming you standard branch is development in the mono repo)
# git checkout -b add-services
githubOrg=FOOBAR
repoList="api backend-service frontend"
repoBranch="development"
serviceDir=services # local directory to pull the other repos in
for repoName in $(echo $repoList); do
echo "Adding ${repoName}.."
git subtree add --prefix=${serviceDir}/${repoName} https://github.com/${githubOrg}/${repoName} ${repoBranch}
done
# After:
# git checkout development
# git rebase add-services
# git push --force
@berstend
Copy link
Author

berstend commented Mar 5, 2019

There's a surprising amount of outdated or just plain incorrect info on the internet regarding this. The above will preserve the history of each service so git blame/lens continues to work. The heavy lifting is done by git subtree add.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment