I started on a simple task in the main branch. ya' know the type of task where "this is too simple even to bother with a git branch"... the inevitable result was that now I have a lot of unfinished work in the master branch and need to work on other things. How do I move my current work to a new branch?
You can do a checkout and create a new branch with all local and current changes transferred over.
You can switch branches with a dirty tree, as long as the switch doesn't involve modifying dirty files. Since you're creating a new branch it's guaranteed not to:
git checkout -b new-branch
Once you've done that you can commit and switch back to master. You can also commit first, although it's slightly more work, because you need to rollback master to before the commit:
git commit
git branch new-branch
git reset --hard HEAD^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With