Skip to content

Latest commit

 

History

History
28 lines (21 loc) · 879 Bytes

delete-merged-branches.md

File metadata and controls

28 lines (21 loc) · 879 Bytes

Delete Merged Branches

The GitHub workflow can create a lot of branches in your git history. After merging a local branch, delete it using git branch -d <branch name>. When there are lots of local branches to delete, use the following command:

In bash or zsh:

git branch --merged | egrep --invert-match "^\*|main" | xargs git branch -d

Following a similar process in PowerShell:

git branch --merged |
Select-String -NotMatch "^\*|main" |
Foreach-Object{$_.ToString().Trim()} |
Foreach-Object{Invoke-Expression "git branch -d $_"}

Discussion

The bash version works in macOS and the PowerShell version works on Windows. Git must be installed on the Windows computer. The primary branch is named main.

References

More on this method and how to clean up remote branches here.