Created
March 28, 2017 14:20
-
-
Save Tanapruk/e43b73a18f32002d7c2e17b737a16231 to your computer and use it in GitHub Desktop.
Looping through all local git branch and git pull them each
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
function gitPullAllLocal() { | |
#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)" #keep list to a variable | |
ALL_BRANCH_LIST="${ALL_BRANCH_LIST//\*/ }" #replace * character syntax is ${string//substring/replacement} | |
echo "======================================" | |
echo "Module ${GIT_RELATIVE_DIRECTORY}" | |
echo "gonna loop through" | |
echo "${ALL_BRANCH_LIST}" | |
echo "======================================" | |
#loop through each local branch, checkout and pull | |
for branch in ${ALL_BRANCH_LIST} | |
do | |
git checkout ${branch} | |
git pull origin ${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