Skip to content

Instantly share code, notes, and snippets.

@sandrokeil
Created January 5, 2016 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sandrokeil/1889cd068322dc259f23 to your computer and use it in GitHub Desktop.
Save sandrokeil/1889cd068322dc259f23 to your computer and use it in GitHub Desktop.
git-batch-upstream-branch-update
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "First parameter is a file with a list of repos git-batch-upstream-branch-update repos.txt"
fi
ROOTDIR=$(pwd)
cd $ROOTDIR
cat $1 | while read line
do
echo -e "\e[32mUpdate branches of $line\e[0m"
cd $ROOTDIR/$line
git fetch upstream
git checkout master && git pull upstream master && git push origin master
DEVELOP_LOCAL=`git branch -a | egrep "[[:space:]]+develop"`
DEVELOP_UPSTREAM=`git branch -a | grep "upstream/develop"`
DEVELOP_ORIGIN=`git branch -a | grep "origin/develop"`
# local develop branch available
if [ ! -z "$DEVELOP_LOCAL" ]; then
git checkout develop && git pull upstream develop && git push origin develop && git branch -u origin/develop
continue
fi
# origin develop branch not available
if [ -z "$DEVELOP_ORIGIN" ] && [ ! -z "$DEVELOP_UPSTREAM" ]; then
git checkout -b develop && git pull upstream develop && git push origin develop
continue
fi
# origin/local develop branch not created but available
if [ ! -z "$DEVELOP_ORIGIN" ] && [ -z "$DEVELOP_LOCAL" ] && [ ! -z "$DEVELOP_UPSTREAM" ]; then
git checkout -b develop origin/develop && git pull upstream develop && git push origin develop
continue
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment