Last active
April 25, 2017 13:31
-
-
Save dsager/42de7782efe5beee108a to your computer and use it in GitHub Desktop.
Shell Script to Merge Multiple Git Repositories via Subtree Merge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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