Skip to content

Instantly share code, notes, and snippets.

@KeKs0r
Last active October 22, 2022 10:58
Show Gist options
  • Save KeKs0r/b48181fff4ecde695f92083349ddc557 to your computer and use it in GitHub Desktop.
Save KeKs0r/b48181fff4ecde695f92083349ddc557 to your computer and use it in GitHub Desktop.
Git Clean Branches
# Delete branches that were deleted on remote
alias git.clean_remote_deleted='git fetch --all -p; git branch -vv | grep ": gone]" | awk '"'"'{ print $1 }'"'"' | xargs -n 1 git branch -D'
# Delete branches that have been merged into main/dev/prod/master
alias git.clean_locally_merged='git branch --merged | egrep -v "(^\*|main|master|dev|prod)" | xargs git branch -d'
alias git.clean='git.clean_remote_deleted && git.clean_locally_merged'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment