Skip to content

Instantly share code, notes, and snippets.

@rubenmromero
Last active February 19, 2018 23:24
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 rubenmromero/42f1e2e7b45c919f4399e9be81479727 to your computer and use it in GitHub Desktop.
Save rubenmromero/42f1e2e7b45c919f4399e9be81479727 to your computer and use it in GitHub Desktop.
Bash :: Pull changes from the origin (develop if it exists and master branches) to all Git repositories cloned in a workspace
#!/bin/bash
#
# Commands Definition
#
ECHO="echo -e"
TPUT_BOLD="tput bold"
TPUT_RED="tput setaf 1"
TPUT_OFF="tput sgr0"
#
# Variables Definition
#
WORKSPACE=<git_repos_dir>
#
# Main
#
cd $WORKSPACE
for REPO in $(find . -mindepth 1 -maxdepth 1 -type d)
do
cd $REPO
if [[ $(git diff --exit-code) ]]
then
$ECHO "\n$($TPUT_BOLD)$($TPUT_RED)Pull process aborted due to there are untracked changes in '$(basename $REPO)' repository$($TPUT_OFF)\n"
exit 1
else
$ECHO "\n$($TPUT_BOLD)Pull changes from the origin to '$(basename $REPO)' repository:$($TPUT_OFF)"
git fetch -p
[[ $(git ls-remote --exit-code . develop) ]] && git checkout develop && git pull
git checkout master && git pull
fi
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment