Last active
February 19, 2018 23:24
-
-
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
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
#!/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