Reputation: 1510
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:
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.Thanks in advance!
Upvotes: 34
Views: 25818
Reputation: 133008
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.
Upvotes: 6
Reputation: 37916
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).
Upvotes: 1
Reputation: 512
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.
Upvotes: 12