33

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!

KarateSnowMachine
  • 1,490
  • 2
  • 13
  • 17

3 Answers3

12

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.

Community
  • 1
  • 1
Marcin Zalewski
  • 512
  • 3
  • 8
6

I'd have a common denominator branch for example "develop", where all my feature-branches would branch off from.

develop
|----featureA
|----featureB
|----featureC

Then once you want to test something out, just merge from the feature branches into develop in the combo you want, e.g.

git checkout develop
git merge featureA featureB
./test.sh

And keep the commit if you are happy with the test. If not do

git reset --hard HEAD^

and you are back to develop the way it was before you made the merge. This way you only need your feature branches and you can experiment with them in any combinations. Just remember as long as you have committed anything you can ALWAYS revert to that state by checking the reflog.

And for your git commit -a problems, do

git reset --soft HEAD^

and you have the index the way it was just before you made the commit. Then just switch to another branch and commit there instead.

rtn
  • 127,556
  • 20
  • 111
  • 121
  • I would just like to add that you probably want to make sure to use `git merge --no-ff featureA featureB` to make sure that you can go back in case of a fast forward. – KarateSnowMachine Nov 21 '13 at 16:46
1

In Git, there are several ways to integrate changes from one branch into another: Merge branches, Rebase branches, or Apply separate commits from one branch to another (cherry-pick).

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259