Fork me on GitHub

Friday, November 6, 2009

Git - Branch Per Feature Experiment

I am sure others are using Git like this before but these are my thoughts I collected over sometime using Git. I have been using Git for over a year now but mostly for my Watir projects where I haven't had a big chance to work with branches other than master till now. My current project has given me an opportunity to use Git in a different perspective. I have been observing that I almost never use master but always am in some branch working and constantly merging with master. And the branch I work on is something related to the feature I am working at that point of time or exploring.
To illustrate the point better, I thought a picture will illustrate the point better :).

As you see in the picture I am currently working on tagging feature but there seems to be other features as branches there. I am exploring the option of text search and well as bookmarking a search for projects. So if I want to work on some other feature I switch the branch and work. Once the feature I am working on is done I switch to master, merge the feature with main branch, pull from remote repo, fix any merge conflicts and commit the feature to master before pushing it to remote repo. Then the branch gets deleted. If any work needs to be done on the feature the branch is recreated.

This seems to be my work pattern for the past few months. Using branch per feature importantly helps in keeping concerns of different features separate while working on them. As well working on a project where spiking is important creating branches for spikes seems to be a good option for me. Sometimes when I want some parts of the spike may be just a commit cherry picking also helps me a lot. Most of this seems easy and possible now because the cost of branching and merging is less in Git. The same approach will be painful in VCS like svn.

This is just sharing of my experience. I am exploring better ways to use Git. Let me know if you have found good ways of using Git or similar DVCS.


Darrell said...

Now admittedly I don't know Git very well, but I do know doing branch-per-feature with SVN isn't that bad at all:

Sai Venkatakrishnan said...

Absolutely.. It is not to say that this technique is not possible with SVN or any other version cotrol. I have worked with both these version controls. It is just that GIT makes built with merging as first class candidate in mind.

Darrell said...

I've heard merging is much easier, and often less often required, with Git rather than SVN and the like.