Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.