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?
+4
A:
You could git stash it!
git stash
change to new branch:
git checkout -b new-branch
Pop it when you're done:
git stash pop
Unless you already commited them. Did you?
Thiago Silveira
2010-06-21 21:25:12
no had not commited them
Arthur Ulfeldt
2010-06-21 21:40:34
Then it's easy. Just use git stash and you will get a clean working directory. Do your changes, commit etc., when you're done, git stash pop. If there are no conflicts, that's it. Otherwise, you can follow the documentation in the "git stash" link. I did not understand the branch part of your edit, though.
Thiago Silveira
2010-06-21 22:17:06
the goal was to have the dirty parts of the master branch become the dirty parts of new-branch and leave master clean.
Arthur Ulfeldt
2010-06-22 17:59:52
If you use git stash, master will be clean already. git stash kinds of stores all your dirty files in another place, and clean your tree. Then, you can make all the changes and commits happily, without clutter. If you want to restore the dirty files, just use git stash pop. You can also stack git stashes. In that case, use git stash list to see available stashes
Thiago Silveira
2010-06-22 21:45:23
See this article: http://ariejan.net/2008/04/23/git-using-the-stash/
Thiago Silveira
2010-06-22 22:02:05
+8
A:
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^
Michael Mrozek
2010-06-21 21:26:40