Arno just wrote about his solution to forgetting what git branch you’re on. I suffer from the same problem – I’d forget me own head if it wasn’t screwed on – but I came up with a different solution. :)
I’m been using git-svn more and more, to the point where I actually won’t write code without it if I expect the patch to take more than a few hours. I’ve accumulated several of these git-svn repos now (often within svn) and I’ve been getting more comfortable working with git, so I’ve started performing minor branch surgery.
say you were on branch foo yesterday, hacking away at a cool feature. Today, you start thinking about feature bar, and hack a bit on that. A few commits later, you remember where you’re committing to, and realise this feature doesn’t belong in that branch. However, it does *depend* on feature foo, or at least you know you’ll be dcommitting foo before bar, so you at least have things in the right order.
Now, first you create a branch to keep bar safe.
git checkout -b bar
now that that’s safe… well, I’m sure there’s a better way to do this, but the *easy* way is to first get rid of foo:
git branch -d foo
then look up the hash of the last commit that actually should belong to foo (copy&paste is your friend):
run over to that commit:
git checkout <hash>
and recreate the branch there:
git checkout -b foo
ta-daa! now branch foo has gone back in time to where it should have ended, and branch bar builds on foo with your latest commits. :) and if you’d forgotten to create bar first, git would have refused to delete foo, so you don’t have to worry much about losing anything to a typo (so long as that typo is not -D. stay away from the dragons ;)
oh, and do remember to go back to branch bar before you continue hacking. :)