user4385532
user4385532

Reputation:

Forgot to do git flow feature start; what now?

My local repository is on branch develop.

We're using Git Flow and I'm supposed to work on a new feature on a separate branch. Normally, I'd do git flow feature start "whatever" before commiting my changes; this time, however, I forgot. Fortunatelly I didn't push this mess yet.

Now I can obviously rescue the situation by (a) copy-pasting my current work to another directory (b) undoing my last unpushed commits from develop; (c) issuing git flow feature start "whatever"; (d) copy-pasting my work from this other directory onto my local git repo; (e) re-commiting.

I'm curious, however, if this can be avoided? That is: if I can create this branch I did not create on time and move my commits and current work to this branch without copy-pasting files? What git commands would I have to issue to achieve this?

Upvotes: 0

Views: 1001

Answers (2)

VJPPaz
VJPPaz

Reputation: 1015

If your develop branch is not yet pushed to origin, do it this way:

  1. commit all your updates to the branch you are working right now. e.g develop.
    • Commit only not sync
  2. Create a new feature branch base on your current local develop branch. feature/"whatever"
  3. Then hard reset your local develop branch base on your origin/develop.

Conclusion: This way you won't rewrite all your changes, the develop branch is the same as before, there is not additional stashes, git flow recognizes the changes you made and it works perfectly even when you already committed several changes to your local develop branch.

Upvotes: 0

user10686911
user10686911

Reputation:

I think this should work:

git stash to save current state

git reset --hard <hash> to reset to previous commit

git checkout -b feature/awesome-feature to create a new branch

git stash apply to reapply all your work

Now, you should have all your work in your feature branch with a clean master branch

Upvotes: 1

Related Questions