Skip to content

Instantly share code, notes, and snippets.

@dsager
Last active April 25, 2017 13:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsager/42de7782efe5beee108a to your computer and use it in GitHub Desktop.
Save dsager/42de7782efe5beee108a to your computer and use it in GitHub Desktop.
Shell Script to Merge Multiple Git Repositories via Subtree Merge
#! /bin/sh
# based on https://help.github.com/articles/working-with-subtree-merge
# Copyright (c) 2014 Daniel Sager
# License: MIT, https://gist.github.com/dsager/0edcbf806b5b86e78455#file-2014
REPOS="front-end back-end"
BRANCHES="develop master"
DIR="monolith"
# create a new repo
mkdir ${DIR}
cd ${DIR}
git init
echo "# ONE" >> README.md
git add README.md
git commit -m "initial commit"
# create branches
for branch in ${BRANCHES}; do
git checkout -b ${branch}
done
for repo in ${REPOS}; do
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "+ setting up ${repo}"
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++"
remote="git@github.com:Devex/${repo}.git"
git remote add -f ${repo} ${remote}
for branch in ${BRANCHES}; do
echo "--------------------------------------------------"
echo "- merging ${repo}/${branch}"
echo "--------------------------------------------------"
git checkout ${branch}
git merge -s ours --no-commit ${repo}/${branch}
git read-tree --prefix=${repo}/ -u ${repo}/${branch}
git commit -m "Subtree merged in ${repo}"
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment