Create Git branch with current changes

Viewed 656772

I started working on my master branch thinking that my task would be easy. After a while I realized it would take more work and I want to do all this work in a new branch.

How can I create a new branch and take all these changes with me without dirtying master?

6 Answers

I see that the most of the answers here are outdated. There is no need to do stash and pop with the new switch command.

git switch -c new_branch -m

will create a new branch named "new_branch", switch to it it and bring along all uncommitted changes as modified files. You can then continue working on the changes or commit them to the new branch etc.

Related