Skip to content

Instantly share code, notes, and snippets.

@gabmontes
Last active September 1, 2022 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabmontes/6ff956bb844a8a0ad4e92159a23d94fb to your computer and use it in GitHub Desktop.
Save gabmontes/6ff956bb844a8a0ad4e92159a23d94fb to your computer and use it in GitHub Desktop.
Prune repo and remove local branches deleted in origin
#!/bin/bash
if [ ! -d .git ]; then
echo Not a git repo
exit
fi
if ! (git remote | grep -q origin); then
echo No origin remote
exit
fi
git fetch origin
git remote prune origin
git branch -vv | grep -v -e '*' -e '^\s.master\s.' -e '^\s.develop\s.' -e '^\s.prod\s.' | awk '/: gone]/{print $1}' | xargs git branch -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment