2

I'm just getting to the stage where something like git flow is going to come in very handy with my project but I'm a bit unsure as to how to swap between features when the feature I'm currently working on isn't quite done.

So if I have a project and I do

$ git flow feature start feature1

then do some work but not quite get it to the stage where I'm happy to commit it before I need to head off and work on another issue, what should I do with my work before I do

$ git flow feature start feature2

?

Is git stash the correct way to go? It doesn't quite seem to do what I want it to do and looks like it could get quite messy quite quickly. But I definitely don't want to commit my changes and it seems silly to have re-clone the entire repo in another directory so I can work on it separately.

bodger
  • 1,112
  • 6
  • 24

2 Answers2

1

This is kind of the rationale for git stash!

That said, you could just create a commit, and then do git reset --soft HEAD^ when you come back to it (which deletes the commit, but retains the changes in your working copy).

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
  • Ahah - this seems like a plan to me. I just have a feeling that all the stashes in the list might get unwieldy and confusing after a very short time so I'm a bit wary of using it. The git reset route seems a lot nicer to me. Thanks. – bodger Aug 25 '16 at 12:05
0

To store the changes locally without pushing them to the remote repository i simply commit every time before switching the branch. At the End before i push i will then squash all the relevant commits to a single one containing all the changes.

You can find a description for squashing commits right here

Community
  • 1
  • 1
Abaddon666
  • 1,533
  • 15
  • 31
  • The thing is, I don't always want to commit the changes - even locally - before I switch branches because it's often hard to figure out what I was doing or where I was up to when I switch back. – bodger Aug 25 '16 at 12:01
  • 1
    I quite often do incremental commits, and then using `git rebase` I will consolidate all the changes into a single, or several, logical commits. Never be afraid to commit often and early, as you can easily rewrite the history of the branch with git. **NOTE:** You would never rebase and force push on the develop or master branch, but in a feature or release branch, it's all good. – Gary Ewan Park Aug 25 '16 at 12:12