Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Discipline: combining multiple feature branches, but still keeping them separate?

Tags:

git

git-branch

The current project I'm working on, I am trying to explore a bunch of different ideas which usually manifest themselves as a bunch of feature branches. The features I'm working on are generally orthogonal to one another, so there are times when I want to merge all of these features (or some subset of the features) and test them out together.

So far my workflow has been this -- I have branches featureA, featureB, featureC and I'll have a branch called featureA_featureB and then another one like featureA_featureB_featureC, etc.

I am having 2 problems:

  • The naming scheme is terribly cumbersome and generates a lot of branch clutter
  • Since I'm testing the branch with the features that are merged together, I tend to accidentally commit to the combination branch rather than the individual branch. So for example, I think of an improvement to featureC, but since I'm in the featureA_featureC branch, I accidentally commit to this branch instead (I really need to stop using git commit -a). Then I have to cherry pick the commit or do some other crazy stuff to get the commit to the right place.
  • I just feel like there's some better way to accomplish this...

Thanks in advance!

like image 736
KarateSnowMachine Avatar asked Feb 22 '11 18:02

KarateSnowMachine


People also ask

Can I merge two feature branches?

Merge branchesMerging your branch into master is the most common way to do this. Git creates a new commit (M) that is referred to as a merge commit that results from combining the changes from your feature branch and master from the point where the two branches diverged.

Should you close branches after merge?

When you're done with a branch and it has been merged into master, delete it. A new branch can be made off of the most recent commit on the master branch. Also, while it is ok to hang onto branches after you've merged them into the master they will begin to pile up.

What is the best branching strategy in git?

Build your strategy from these three concepts: Use feature branches for all new features and bug fixes. Merge feature branches into the main branch using pull requests. Keep a high quality, up-to-date main branch.


1 Answers

I was going to write an answer of my own, but then I found this great answer (and a great question). It does not give you a single way to do things, but upon a careful reading, you should be able to find a workflow that suits your situation.

like image 62
Marcin Zalewski Avatar answered Sep 28 '22 05:09

Marcin Zalewski