Skip to content

Instantly share code, notes, and snippets.

@deckerego
Created December 6, 2013 22:17
Show Gist options
  • Save deckerego/7833085 to your computer and use it in GitHub Desktop.
Save deckerego/7833085 to your computer and use it in GitHub Desktop.
Mass-create branches in multiple Git repos and push them remote
#!/bin/sh
PROJECTS="Project_1 Project_2 Project_3"
BRANCH="$1"
if [[ -z "$BRANCH" ]]; then
echo "Usage $0 BRANCH_NAME"
exit -1
fi
for PROJECT in $PROJECTS
do
echo "Creating $PROJECT branch $BRANCH"
CURRENT_DIR=$PWD
cd $PROJECT
git checkout -b "$BRANCH"
git config "branch.$BRANCH.remote" origin
git config "branch.$BRANCH.merge" "refs/heads/$BRANCH"
git push origin "$BRANCH"
SUCCESS=$?
if [[ $SUCCESS -ne 0 ]]; then
echo "** ERROR CREATING BRANCH $BRANCH FOR REPO $PROJECT **"
exit $SUCCESS
fi
cd $CURRENT_DIR
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment