Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i move my current work to a topic branch?

Tags:

git

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?

like image 685
Arthur Ulfeldt Avatar asked Jun 21 '10 21:06

Arthur Ulfeldt


People also ask

Can I create a new branch with current changes?

You can do a checkout and create a new branch with all local and current changes transferred over.


1 Answers

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^
like image 163
Michael Mrozek Avatar answered Sep 18 '22 13:09

Michael Mrozek