Skip to content

Instantly share code, notes, and snippets.

@siwonpawel
Last active June 8, 2022 07:44
Show Gist options
  • Save siwonpawel/75ce2ab8d38fdaa690458074af4fcad5 to your computer and use it in GitHub Desktop.
Save siwonpawel/75ce2ab8d38fdaa690458074af4fcad5 to your computer and use it in GitHub Desktop.
Update all git-repositories inside a root folder
#!/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