Skip to content

Instantly share code, notes, and snippets.

@egoens
Last active May 29, 2020 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egoens/0dbf32bcd9247e4a84e12cb356a1f07d to your computer and use it in GitHub Desktop.
Save egoens/0dbf32bcd9247e4a84e12cb356a1f07d to your computer and use it in GitHub Desktop.
Pull current repo and any immediate sub-repos
# pull subrepos
gplall () {
# look into immediate subdirectories
for dir in ./*/
do
cd ${dir}
# check if exit status of above was 0, indicating we're in a git repo
if [ -d ".git" ]
then
# capture name of current branched checked out
curr_branch=`git rev-parse --abbrev-ref HEAD`
# checkout and pull master
echo "Updating ${dir%*/}..." && git checkout master && git pull
# checkout original branch if not 'master'
if [ "${curr_branch}" != "master" ]
then
echo "Checking out ${curr_branch} branch..." && git checkout "${curr_branch}"
fi
fi
cd ..
done
### update root repo
# capture name of current branched checked out
curr_branch=`git rev-parse --abbrev-ref HEAD`
# checkout and pull master
echo "Updating ${PWD##*/}..." && git checkout master && git pull
# checkout original branch if not 'master'
if [ "${curr_branch}" != "master" ]
then
echo "Checking out ${curr_branch} branch..." && git checkout "${curr_branch}"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment