-1

I usually start editing files by creating a new branch: git checkout new-feature

But this time i forgot to create a new branch and started editing files. I have not added or committed anything yet.

Is there a way I can make a branch now and still have all the edits I've made thus far?

birdy
  • 8,476
  • 22
  • 98
  • 170
  • Just make a new branch and check it out. – Biffen Feb 03 '15 at 17:49
  • possible duplicate of [Move existing, uncommited work to a new branch in Git](http://stackoverflow.com/questions/1394797/move-existing-uncommited-work-to-a-new-branch-in-git) – Andrew C Feb 03 '15 at 19:47

1 Answers1

2

If you want to create a new branch off the current branch with all the work you are currently working on (i.e. with a dirty working directory), you can just create the branch and switch to it:

git checkout -b new-feature

Git will not touch your changes at all. And if Git had a problem that would require Git to change things, it wouldn’t do so but instead stop and tell you that you can’t do it without losing changes.

jub0bs
  • 46,795
  • 22
  • 148
  • 157
poke
  • 307,619
  • 61
  • 472
  • 533