tags:

views:

1160

answers:

1

I started some work on a new feature. After coding for a bit I decided this feature should be on its own branch. How do I move the existing uncommitted changes to a new branch and reset my current one?

I want to be sure that I can reset my current branch while preserving work on the uncompleted feature.

+14  A: 

use git checkout -b <new-branch>

this will leave your current branch as is, create and checkout a new branch and keep all your changes. you can then make a commit with git add <files> and commit with git commit to your new branch

knittl
Just to make sure, I need to commit the unfinished feature BEFORE I reset my original branch? Or will those uncommitted files be preserved regardless of committing?
TheDeeno
you don’t _reset_ your original branch, it stays at it is. the last commit on <old-branch> will still be the same. therefor: you checkout -b and then commit
knittl
oh yeah. duh. thanks.
TheDeeno
FYI: changes in working directory and changes staged in index do not belong to a branch. `git checkout -b <new branch>` changes where those changes would end in.
Jakub Narębski