{"thread":{"id":"8825","subject":"Re: How to create & switch to a branch after changes have already been made?","startedAt":"2007-07-03T03:05:35Z","lastAt":"2007-07-03T03:05:35Z","messageCount":1,"participants":["linux@horizon.com"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"46315","messageId":"20070703030535.2958.qmail@science.horizon.com","threadId":"8825","inReplyTo":null,"subject":"Re: How to create & switch to a branch after changes have already been made?","fromName":"","fromEmail":"linux@horizon.com","sentAt":"2007-07-03T03:05:35Z","receivedAt":"2007-07-03T03:05:35Z","isPatch":false,"sender":{"key":"linux@horizon.com","avatar":null},"body":"The magic you're looking for is \"git checkout -b <branch>\"\n\nYou can do that even with uncommitted changes hanging around.\nBecause you don't specify a commit to check out, it just \"checks out\nthe HEAD again\", which does nothing.  The only thing left is the\npart that creates and switches to a new branch.\n\nNow, if you've already created the branch, you can either do:\ngit checkout <newbranch>\nwhich, since <newbranch> equals HEAD, just switches the HEAD symlink\nwithout actually changing the checked-out commit.\n\nOr, if you want to be really low-level,\n\ngit-update-ref HEAD <newbranch>\n\nWhich is the underlying tool that git checkout uses.\nIt bypasses all the safety checkes, but it might be easiest to understand.\n\n\nNow, if you've already committed, you can just do:\n\ngit checkout -b <newbranch>\ngit branch -f <oldbranch> HEAD^\n\n\nAdmittedly, I sometimes with for a \"git commit -b <branch>\" shortcut.\n"}]}