Delete local branches that are already merged
git delete all merged branches | clean up old local branches | too many local branches | git | branch | cleanupCaution: This command changes the system. Understand what it does before you run it.
git branch --merged main | grep -vE '^[*+]|^\s*(main|main|master|develop)$' | xargs -r git branch -dDetermines all local branches whose commits are already contained in the main branch, filters out the currently checked out branch and the usual main branches, and deletes the rest. Since git branch -d only removes fully merged branches, no work is lost. Remote branches remain untouched.
Note: Run the first part up to | xargs on its own beforehand to check the list. git fetch --prune removes stale remote-tracking branches.
Also searched as
- git delete all merged branches
- clean up old local branches
- too many local branches