Last active
June 8, 2022 07:44
-
-
Save siwonpawel/75ce2ab8d38fdaa690458074af4fcad5 to your computer and use it in GitHub Desktop.
Update all git-repositories inside a root folder
This file contains hidden or 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 | |
# Update git repositorties inside a folder | |
# how to execute: | |
# chmod +x git-update.sh | |
# ./git-update.sh ROOT_FOLDER_PATH | |
if [ "$#" == "1" ]; then | |
cd $1 | |
fi | |
for FOLDER in $(ls -d */); | |
do | |
echo "***** $FOLDER *****" | |
cd $FOLDER | |
if git status &>/dev/null; then | |
echo -e "\t\tDirectory is under the control of git" | |
ACTIVE_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
echo -e "\t\tUpdating all remotes" | |
git fetch --all &>/dev/null | |
if [ "$ACTIVE_BRANCH" == "master" ]; then | |
echo -e "\t\t$ACTIVE_BRANCH branch is active, updating..." | |
git pull &>/dev/null | |
else | |
echo -e "\t\tupdating master branch..." | |
git fetch origin master:master &>/dev/null | |
fi | |
else | |
echo "Directory is not under the control of git" | |
fi | |
cd .. | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment