Skip to content

Instantly share code, notes, and snippets.

@innomatics
Created October 6, 2022 12:02
Show Gist options
  • Save innomatics/e9eca3b95644982bdffb0aac0258b842 to your computer and use it in GitHub Desktop.
Save innomatics/e9eca3b95644982bdffb0aac0258b842 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Every folder in the script path should be a git repository.
# Update each folder/repo with a remote pull (if they are on the default branch).
set -e
REMOTE=origin
for folder in $(find .. -mindepth 1 -maxdepth 1 -type d); do
if [ -d $folder/.git ]; then
pushd $folder
default_branch=$(git remote show $REMOTE | sed -n '/HEAD branch/s/.*: //p')
current_branch=$(git branch --show-current)
if [ "$default_branch" == "$current_branch" ]; then
echo git pull $REMOTE $current_branch
else
echo Skipping repo in $folder \($current_branch\) because its not on $default_branch.
fi
popd
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment