Skip to content

Instantly share code, notes, and snippets.

View gvannest's full-sized avatar

Gautier Vanneste gvannest

View GitHub Profile
@gvannest
gvannest / gitconfig-clean-git-aliases
Created September 19, 2024 12:34
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