Reputation:
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
Reputation: 1015
If your develop branch is not yet pushed to origin, do it this way:
develop
.
develop
branch. feature/"whatever"
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
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