-
-
Save nathanbrauer/ab1fc0ac4e54981599f02d45b346aaf3 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
#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