This command executed in in project directory with bash will delete all local branches which were already merged into master:
git branch --merged | egrep -v "(^\*|master)" | xargs git branch -d
Explanation:
git branch --merged - list all merged branches
egrep -v "(^\*|master)" - grep "master" from provided lines one by one (piped from git branch above)
xargs git branch -d - delete filtered branches (piped from egrep above)
git branch --merged - list all merged branches
egrep -v "(^\*|master)" - grep "master" from provided lines one by one (piped from git branch above)
xargs git branch -d - delete filtered branches (piped from egrep above)
Same sort of command in PowerShell:
git branch --merged main | ForEach-Object { if ($_ -ne '* main' -and $_ -ne '* master') { git branch -d $_.trim() } }
No comments:
Post a Comment