Skip to content

Instantly share code, notes, and snippets.

@keklikhasan
Created July 25, 2018 07:43
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 keklikhasan/7853bc36a0b275d16160523b04b62449 to your computer and use it in GitHub Desktop.
Save keklikhasan/7853bc36a0b275d16160523b04b62449 to your computer and use it in GitHub Desktop.
git fetch and pull all projects
#!/bin/bash
# TODO get params from arguments add git command for pass prompt vs..
WORKING_DIRECTORY="[WORKING_DIRECTORY]"
TARGET_BRANCH="develop"
#trim branch
TARGET_BRANCH="$(echo $TARGET_BRANCH| xargs)"
#trim working directory
WORKING_DIRECTORY="$(echo $WORKING_DIRECTORY| xargs)"
#remove last '/' from working directory
WORKING_DIRECTORY=${WORKING_DIRECTORY%/}
#change working directory
echo "###### - cd to working directory '$WORKING_DIRECTORY' - ######"
cd $WORKING_DIRECTORY
#list all projects
echo "###### - List of projects - ######"
for i in $(ls -d */); do echo ${i%%/}; done
#check each projects
for i in $(ls -d */); do
DIR=${i%%/}
echo "###### - '$DIR' cd project dir - ######"
cd "$WORKING_DIRECTORY/$DIR"
if [ -d .git ]; then
echo "###### - '$DIR' is git repo will be process - ######"
branch="$(git symbolic-ref HEAD 2>/dev/null)"
branch=${branch##refs/heads/}
if [ "$branch" = "$TARGET_BRANCH" ]; then
git branch -vv
echo "###### - '$DIR' is git repo will be fetch '$branch' - ######"
git fetch
git branch -vv
echo "###### - '$DIR' is git repo will be pull '$branch' - ######"
git pull
else
echo "###### - '$DIR' is git repo is not on target branch target branch '$TARGET_BRANCH' != '$branch' - ######"
fi
else
echo "###### - '$DIR' is not a git repo will be skipped - ######"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment