Dane O'Connor Dane O'Connor - 13 days ago 5x
Git Question

Move existing, uncommited work to a new branch in Git

I started some work on a new feature and 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 reset my current branch while preserving existing work on the new feature.


Use the following:

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 to your new branch with:

git commit

The changes in the working directory and changes staged in index do not belong to any branch yet. This changes where those changes would end in.

You don't reset your original branch, it stays as it is. The last commit on <old-branch> will still be the same. Therefore you checkout -b and then commit.