Skip to content

Instantly share code, notes, and snippets.

@RyanSiu1995
Last active October 1, 2021 14:06
Show Gist options
  • Save RyanSiu1995/da44646f747623d9f51ec52724f16066 to your computer and use it in GitHub Desktop.
Save RyanSiu1995/da44646f747623d9f51ec52724f16066 to your computer and use it in GitHub Desktop.
Sync the local branches with origin remote
#!/bin/bash -e
git fetch origin -p
REMOTE=$(git branch -r | sed "s/origin\///g")
BRANCHES=$(git branch | awk -F ' +' '! /\(no branch\)/ {print $2}')
for branch in $BRANCHES; do
if [[ -z $(echo $REMOTE | grep -w $branch) ]]; then
git branch -D $branch
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment