{"thread":{"id":"8069","subject":"Switching branch before commit","startedAt":"2007-05-10T19:43:23Z","lastAt":"2007-05-10T20:08:44Z","messageCount":3,"participants":["Ron Parker","Adam Roben","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"41764","messageId":"769697AE3E25EF4FBC0763CD91AB1B0201D496E7@MBGMail01.mobot.org","threadId":"8069","inReplyTo":null,"subject":"Switching branch before commit","fromName":"Ron Parker","fromEmail":"ron.parker@mobot.org","sentAt":"2007-05-10T19:43:23Z","receivedAt":"2007-05-10T19:43:23Z","isPatch":false,"sender":{"key":"ron.parker@mobot.org","avatar":null},"body":"I know this is probably a FAQ and I thought I found it somewhere once,\nbut... How do I commit changes from in my working directory to another\n(possibly non-existent) branch?\n \nAll too often I am working on changes and realize I am sitting on master\nor a topic branch and I need to commit my mods to different branch.  I\nreally don't like:\n \n    git commit\n    git branch <other-branch>\n    git reset --hard HEAD^\n \nIs there anything like:\n    git commit -b <other-branch> [<file>...]?\n\nIf not, would patches to implement such a change be accepted?\n"},{"id":"41768","messageId":"CAD30837-B0EB-4752-B563-DE2517CFF0A1@apple.com","threadId":"8069","inReplyTo":"769697AE3E25EF4FBC0763CD91AB1B0201D496E7@MBGMail01.mobot.org","subject":"Re: Switching branch before commit","fromName":"Adam Roben","fromEmail":"aroben@apple.com","sentAt":"2007-05-10T20:02:04Z","receivedAt":"2007-05-10T20:02:04Z","isPatch":false,"sender":{"key":"aroben@apple.com","avatar":"https://gravatar.com/avatar/9d3697e1de53890adf241331f4b970bdd2b18962b2ff0b8028ebb00e085807f8?d=mp&s=160"},"body":"On May 10, 2007, at 12:43 PM, Ron Parker wrote:\n\n> I know this is probably a FAQ and I thought I found it somewhere once,\n> but... How do I commit changes from in my working directory to another\n> (possibly non-existent) branch?\n>\n> All too often I am working on changes and realize I am sitting on  \n> master\n> or a topic branch and I need to commit my mods to different branch.  I\n> really don't like:\n>\n>    git commit\n>    git branch <other-branch>\n>    git reset --hard HEAD^\n>\n> Is there anything like:\n>    git commit -b <other-branch> [<file>...]?\n>\n> If not, would patches to implement such a change be accepted?\n\n    You can do this simply by doing the following:\n\ngit checkout -b <other-branch>\ngit commit\n\n    The changes in your working tree will be carried over to <other- \nbranch> when you do the git-checkout command.\n\n-Adam\n"},{"id":"41771","messageId":"7v3b24jvar.fsf@assigned-by-dhcp.cox.net","threadId":"8069","inReplyTo":"769697AE3E25EF4FBC0763CD91AB1B0201D496E7@MBGMail01.mobot.org","subject":"Re: Switching branch before commit","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-05-10T20:08:44Z","receivedAt":"2007-05-10T20:08:44Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Ron Parker\" <ron.parker@mobot.org> writes:\n\n> I know this is probably a FAQ and I thought I found it somewhere once,\n> but... How do I commit changes from in my working directory to another\n> (possibly non-existent) branch?\n>  \n> All too often I am working on changes and realize I am sitting on master\n> or a topic branch and I need to commit my mods to different branch.  I\n> really don't like:\n>  \n>     git commit\n>     git branch <other-branch>\n>     git reset --hard HEAD^\n\nI do not like that either, and I wouldn't do that.  In fact that\nwould not work, as \"git branch\" would not switch to the other\nbranch you just created.\n\nI would do:\n\n\t$ git checkout -b other-branch\n\nwhich would create and switch to other-branch, based on the\ncurrent HEAD (in your case, 'master'), WITHOUT disrupting what\nis in your working tree and the index.\n\nand then (perhaps after working on it some more to perfection):\n\n\t$ git commit\n\nto commit that work I (mistakenly) started on 'master' in that\nother branch.  Then I would come back to master:\n\n\t$ git checkout master\n"}]}