Created
July 25, 2018 07:43
-
-
Save keklikhasan/7853bc36a0b275d16160523b04b62449 to your computer and use it in GitHub Desktop.
git fetch and pull all projects
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 | |
# 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