git branching model: choose branches for deletion – see whats remaining for the merge

04 / Mar / 2011 by Salil 0 comments

This post is for people who are already familiar with Git and work on multiple branches (esp. feature branches).
By practice, feature branches are the branches created from a root branch (master or any other as per your branching model) and once feature is complete/tested – they are merged back into the same root branch.

Working in such a manner is pretty nice and clean. But things start getting messy if we don’t delete the branches on time (esp. after merging into root branch). In that case when we run command –
git branch
It shows us zillions of branches and we start getting feeling to get a rid of all futile branches. But we don’t know which branches are already merged and which are still under progress or yet to be tested.

Solution to this problem:
# I am assuming that your root branch is master
git checkout master
git branch –merged

Above command will show you all branches which are already merged into the current branch (master branch in this case). This means you can delete these (feature) branches now.
For deleting a branch on local: git branch {-d | D} ‘feature-branch-1’
For deleting from remote: git push origin :feature-branch-1
I assumed that origin is your remote.

Similarly if you run
git branch –no-merged
It will give a list of branches which are yet to be merged.

Question: I got a list of branches which are not merged yet. Now I want to see the commits in particular branch which are not merged into root branch yet?
git log –pretty=oneline maser..branch1
Again, master is your root branch. And branch1 is your feature branch having commits yet to be merged.

Your comments are always Welcome. Please post if you have any!

Salil Kalia
Salil [at] IntelliGrape [dot] com
Twitter LinkedIn


Leave a Reply

Your email address will not be published. Required fields are marked *