Skip to content

Instantly share code, notes, and snippets.

@glektarssza
Last active April 22, 2025 10:59
Show Gist options
  • Save glektarssza/68a638b143ddf7702e18b7fd014d0959 to your computer and use it in GitHub Desktop.
Save glektarssza/68a638b143ddf7702e18b7fd014d0959 to your computer and use it in GitHub Desktop.
Git Prune Branches (w/ alias version)
[alias]
prune-branches = "!f() { git fetch --prune && for BRANCH in $(git for-each-ref --format '%(refname) %(upstream:track)' refs/heads | awk '$2 == \"[gone]\" {sub(\"refs/heads/\", \"\", $1); print $1}'); do git branch $([[ $@ =~ --force ]] && echo \"-D\" || echo \"-d\") $BRANCH; done };f"
f() {
git fetch --prune && for BRANCH in $(git for-each-ref --format '%(refname) %(upstream:track)' refs/heads | awk '$2 == \"[gone]\" {sub(\"refs/heads/\", \"\", $1); print $1}'); do
git branch $([[ $@ =~ --force ]] && echo \"-D\" || echo \"-d\") $BRANCH;
done
}
f $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment