Skip to content

Instantly share code, notes, and snippets.

@nathanbrauer
Forked from Tanapruk/gitpullalllocal.sh
Last active May 26, 2017 16:01
Show Gist options
  • Save nathanbrauer/ab1fc0ac4e54981599f02d45b346aaf3 to your computer and use it in GitHub Desktop.
Save nathanbrauer/ab1fc0ac4e54981599f02d45b346aaf3 to your computer and use it in GitHub Desktop.
Looping through all local git branch and git pull them each
#if there is a passing argument
if [ -z $1 ]
then
GIT_RELATIVE_DIRECTORY="$(pwd)"
else
GIT_RELATIVE_DIRECTORY=$1
fi
#go to that relative path if exists
cd ${GIT_RELATIVE_DIRECTORY}
CURRENT_BRANCH="$(getCurrentBranch)"
#Checkout develop if detached head
if [ ${CURRENT_BRANCH} = "(HEAD" ]
then
echo 'found detached HEAD gonna checkout develop'
git checkout develop
CURRENT_BRANCH="$(getCurrentBranch)"
fi
ALL_BRANCH_LIST="$(git branch -r)" #keep list to a variable
ALL_BRANCH_LIST="${ALL_BRANCH_LIST// origin\// }" #replace * character syntax is ${string//substring/replacement}
ALL_BRANCH_LIST="$(echo "${ALL_BRANCH_LIST}" | sed "/->/d")"
echo "======================================"
echo "Module ${GIT_RELATIVE_DIRECTORY}"
echo "gonna loop through"
echo "${ALL_BRANCH_LIST}"
echo "======================================"
read -p "Continue? (CTRL+C to cancel)"
#loop through each local branch, checkout and pull
for branch in ${ALL_BRANCH_LIST}
do
git checkout ${branch}
git pull origin ${branch}
git push original ${branch}:v3/${branch}
done
#Revert to current branch
git checkout ${CURRENT_BRANCH}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment