Comment Comment by fphilipe Here's my take on the one-liner that I use via a `git tidy` alias[1]. A few points:* It ensures the default branch is not deleted (main, master)* It does not touch the current branch* It does not touch the branch in a different worktree[2]* It also works with non-merge repos by deleting the local branches that are gone on the remote git branch --merged "$(git config init.defaultBranch)" \ | grep -Fv "$(git config init.defaultBranch)" \ | grep -vF '*' \ | grep -vF '+' \ | xargs git branch -d \ && git fetch \ && git remote prune origin \ && git branch -v \ | grep -F '[gone]' \ | grep -vF '*' \ | grep -vF '+' \ | awk '{print $1}' \ | xargs git branch -D [1]: https://github.com/fphilipe/dotfiles/blob/ba9187d7c895e44c35...[2]: https://git-scm.com/docs/git-worktree parent fphilipe 8 months ago
* It ensures the default branch is not deleted (main, master)
* It does not touch the current branch
* It does not touch the branch in a different worktree[2]
* It also works with non-merge repos by deleting the local branches that are gone on the remote
[1]: https://github.com/fphilipe/dotfiles/blob/ba9187d7c895e44c35...[2]: https://git-scm.com/docs/git-worktree