Skip to content

Instantly share code, notes, and snippets.

@nicholashoule
Last active October 20, 2025 05:34
Show Gist options
  • Save nicholashoule/ff5a00c8f02ea57f0b26889f022620f4 to your computer and use it in GitHub Desktop.
Save nicholashoule/ff5a00c8f02ea57f0b26889f022620f4 to your computer and use it in GitHub Desktop.
Git prune and delete merged local branches

Git

macOS

brew install git

Windows

winget install --id Git.Git -e --source winget

Git prune and delete merged local branches

Prune
git remote prune origin --dry-run
git remote prune origin
Delete (Bash, Zsh)
git branch --merged | grep -v \*
git branch --merged | grep -v \* | xargs git branch -D 
Delete (Powershell)
git branch --merged | Select-String -Pattern '\*' -notMatch
git branch --merged | Select-String -Pattern '\*' -notMatch |  % { $_.split()[0] } | % { git branch -D $_ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment