Skip to content

Instantly share code, notes, and snippets.

@wancw
Created June 19, 2017 08:06
Show Gist options
  • Save wancw/833c243bcfc04fe80e76bc833145c99a to your computer and use it in GitHub Desktop.
Save wancw/833c243bcfc04fe80e76bc833145c99a to your computer and use it in GitHub Desktop.
Update all tracking Git branches
#!/usr/bin/env zsh
ORIG_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
if [[ "$ORIG_BRANCH" == "HEAD" ]] {
ORIG_BRANCH="$(git rev-parse --short HEAD)"
}
for b in $(git branch --track | grep -v 'detached' | sed 's/*//')
do
git checkout "${b}"
git rev-parse --abbrev-ref @{u} && git merge --ff-only
echo
done
LAST_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
if [[ "$ORIG_BRANCH" != "$LAST_BRANCH" ]] {
git checkout --quiet "$ORIG_BRANCH"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment