Skip to content

Instantly share code, notes, and snippets.

@eusonlito
Last active May 12, 2023 16:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eusonlito/d5a3c0168e6e6988729c5eafbf0e44ab to your computer and use it in GitHub Desktop.
Save eusonlito/d5a3c0168e6e6988729c5eafbf0e44ab to your computer and use it in GitHub Desktop.
Update all git branches from remote on all repositories
#!/bin/bash
HERE=$(pwd)
for env in api web; do
echo -e "\nUpdating $env\n"
cd $HERE/$env
CURRENT=$(git rev-parse --abbrev-ref HEAD)
git fetch --all > /dev/null
git remote prune origin > /dev/null
for branch in $(git branch -r | grep -v '\->' | sed 's/origin\///'); do
git checkout $branch > /dev/null
git pull origin $branch > /dev/null
echo ""
done
git checkout $CURRENT > /dev/null
done
echo ""
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment