git branch --merged

One can explore git and discover something new every day. One of my recent discoveries is the --merged option of git branch. As the name suggests, it allows you to list all branches which have been merged as of a specified commit. Conveniently, it defaults to the current commit, so by running:

git branch --merged

you can list all the branches which have already been merged up to the current commit.

This happens to be very useful when cleaning up old feature branches after a release. Normally, this would be boring manual process of listing all the branches, but by chaining --merged with a regexp, and another call to git branch:

git branch --merged | grep -E "^\s*[[:digit:]]+_" | xargs git branch -d

We get a nice one-liner deleting all the merged branches with names matching the given pattern (here 123_feature_x). Sure, writing this every time would be worse than the naive approach, but it can be wrapped into a function with a short cryptic name to save on the typing.

We're looking for developers to help us save energy

If you're interested in what we do and you would like to help us save energy, drop us a line at

comments powered by Disqus