Roman
Roman

Reputation: 10403

How to create a fresh feature using Git flow?

I started a new feature using Git Flow (feature A) but haven't committed any of my changes yet.

I then needed to create a new feature (feature B) but I don't want it to include my uncommitted changes from feature A.

I can't workout why the new feature didn't begin from the current state of the Develop branch! It includes all of my changes from feature A which haven't yet been committed.

Upvotes: 1

Views: 133

Answers (3)

niculare
niculare

Reputation: 3687

If you are currently on branch featureA with some uncommitted changes and you want to create new branch which does not contain the uncommitted changes, try the following:

git stash
git checkout -b featureB
//now in branch 'featureB` you will no longer have the uncommitted changes
//in order to continue your work on 'featureA':
git checkout featureA
git stash pop

Upvotes: 1

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174457

That's normal behaviour in git and has nothing to do with git flow:
When you switch (a.k.a checkout) a branch and you have uncommitted changes in your working directory there are two possible scenarios:

  1. The checkout of the other branch wouldn't overwrite any of those uncommitted changes: The checkout succeeds and you are now on the checked out branch with the uncommitted changes still in your working directory.
  2. The checkout of the other branch would overwrite some of those uncommitted changes: The checkout fails.

git flow feature start <name> does exactly that: It creates a new branch and checks it out. Because there are no conflicts scenario 1 happens.

Ask yourself this:
If the uncommitted changes wouldn't remain in the working directory after switching your branch, where should they go instead?

As Thomas correctly points out, git stash can help you here. Or you could simply commit the changes to the branch of feature A, because you are supposed to commit often anyway.

Upvotes: 2

Thomas
Thomas

Reputation: 182063

I'm not familiar with Git Flow, but maybe git stash would help here?

Upvotes: 1

Related Questions