Skip to content

Instantly share code, notes, and snippets.

@squio
Created April 10, 2026 09:29
Show Gist options
  • Select an option

  • Save squio/60beed00622b67526e0d28a793b62008 to your computer and use it in GitHub Desktop.

Select an option

Save squio/60beed00622b67526e0d28a793b62008 to your computer and use it in GitHub Desktop.
git: delete squash-merged branches when delete branch on merge is enabled in the remote service (GitHub, GitLab etc)
delete-merged() {
git branch --format '%(if:equals=gone)%(upstream:track,nobracket)%(then)%(refname:short)%(end)' --omit-empty | while read branch; do
git branch -D "$branch"
done
}
@squio

squio commented Apr 10, 2026

Copy link
Copy Markdown
Author

Add this to .zshrc and invoke on the command line:

% delete-merged
Deleted branch TEMPORARY/add-guard-and-logging (was f829ccf33).
Deleted branch bugfix/onboarding-customers (was 0e1006b0f).
Deleted branch bugfix/keep-initial-data-when-possible (was 2fb8f94a0).
Deleted branch chore/add-premium-flag-to-enum_item_tag (was 40d027686).
Deleted branch feature/fix-app-sync-issues (was 1013ead83).
Deleted branch hotfix/merge-feature-4235-into-acceptance (was 07103f393).
Deleted branch release/sprint-82 (was 13c765936).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment