Skip to content

Instantly share code, notes, and snippets.

@namuan
Created June 9, 2022 08:21
Show Gist options
  • Save namuan/b7123b8d07ccb99d89a0e2032ddec518 to your computer and use it in GitHub Desktop.
Save namuan/b7123b8d07ccb99d89a0e2032ddec518 to your computer and use it in GitHub Desktop.
function git_delete_missing_remote_branches() {
bold=$(tput bold)
normal=$(tput sgr0)
git fetch -p && for branch in $(git for-each-ref --format '%(refname) %(upstream:track)' refs/heads | awk '$2 == "[gone]" {sub("refs/heads/", "", $1); print $1}'); do echo -n "Delete this branch ${bold}$branch${normal}? [y/n] " && read should_delete && (test "$should_delete" = 'y' && git branch -D $branch || echo "Ignoring branch $branch"); done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment