Skip to content

Instantly share code, notes, and snippets.

@gvannest
Created September 19, 2024 12:34
Show Gist options
  • Save gvannest/b7de82ef0000e65524f7dc43c3c9db8f to your computer and use it in GitHub Desktop.
Save gvannest/b7de82ef0000e65524f7dc43c3c9db8f to your computer and use it in GitHub Desktop.
Git aliases to clean git branches
[alias]
gone = "!f() { git fetch --all --prune; git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -D; }; f"
merged = "!f() { git branch --merged | egrep -v '(^\\*|master|main|dev)' | xargs git branch -D; }; f"
delete = "!f() { for branch in \"$@\"; do git branch -D \"$branch\" && git push origin --delete \"$branch\"; done; }; f"
# usage
# git gone => delete "gone" branches locally and remotely
# git merged => delete "merged: branches locally and remotely
# git delete branche-a branche-b branche-c => delete a, b and c branches locally and remotely
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment