Created
January 5, 2016 22:59
-
-
Save sandrokeil/1889cd068322dc259f23 to your computer and use it in GitHub Desktop.
git-batch-upstream-branch-update
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/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