Git branch and remote cleanup alias
To easily remove git branches and prune orphaned remotes I've created a alias named branch-cleanup
:
First I fetch the remote origin with --prune
, to remove references to deleted branches on the remote:
git fetch origin --prune
Then I list the branches which are merged to origin/master
, I exclude the master branch and pass that list to git branch -d
using xargs
:
git branch --merged origin/master | grep -v 'master$' | xargs git branch -d
To create an alias for this, run the following:
git config --global alias.branch-cleanup "\!git fetch origin --prune && git branch --merged origin/master | grep -v 'master$' | xargs git branch -d"
Written by Koen Punt
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Branch
Authors
niklongstone
41.97K
muzzlefork
11.98K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#