$ git branch --merged origin/master
* master
feature/some-branch
feature/some-other-branch
$ git branch --merged origin/master | grep -v master
feature/some-branch
feature/some-other-branch
Now we can take this result and pipe it into xargs, to run git branch -d passing the output as arguments
$ git branch --merged origin/master
| grep -v master
| xargs -r git branch -d
I've noticed this doesn't always delete all old branches, but it can help. For example, perhaps you had a branch that was a work in progress, or a spike, with changes that aren't merged - this won't be picked up.
You can do one more trick to detect old branches that have no upstream branch anymore:
$ git branch -vv
This will list branches without an upstream branch with gone. Those can generally be deleted too.
No comments:
Post a Comment