{"thread":{"id":"27844","subject":"How to do a fast-forward merge without a checkout?","startedAt":"2011-07-18T14:18:58Z","lastAt":"2011-07-18T16:24:37Z","messageCount":6,"participants":["Patrick Doyle","Johannes Sixt","knittl"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"171576","messageId":"CAF_dkJCvtVqoDmRXMy23ZnZL6iUAVX0nNA9Ev6e4zvBp9mfTpg@mail.gmail.com","threadId":"27844","inReplyTo":null,"subject":"How to do a fast-forward merge without a checkout?","fromName":"Patrick Doyle","fromEmail":"wpdster@gmail.com","sentAt":"2011-07-18T14:18:58Z","receivedAt":"2011-07-18T14:18:58Z","isPatch":false,"sender":{"key":"wpdster@gmail.com","avatar":null},"body":"Huh?  What does he mean by that?\n\nI have the following in my .git/config file:\n\n[remote \"origin\"]\n\tfetch = +refs/heads/*:refs/remotes/origin/*\n\turl = somehost:path/to/repo\n[branch \"master\"]\n\tremote = origin\n\tmerge = refs/heads/master\n[branch \"wpd\"]\n\tremote = origin\n\tmerge = refs/heads/wpd\n\nI have been working on my \"wpd\" branch on a couple of different\nmachines and have been happily committing, pushing, and pulling from\nmy \"origin\" host.  Recently, however, somebody committed a change on\nthe \"master\" branch.  Now, when I do a \"git push\", I get the following\n\n$ git push\nCounting objects: 11, done.\nDelta compression using up to 2 threads.\nCompressing objects: 100% (6/6), done.\nWriting objects: 100% (6/6), 715 bytes, done.\nTotal 6 (delta 4), reused 0 (delta 0)\nTo somehost:path/to/repo\n   e1004df..bad8767  wpd -> wpd\n ! [rejected]        master -> master (non-fast-forward)\nerror: failed to push some refs to 'somehost:path/to/repo'\nTo prevent you from losing history, non-fast-forward updates were rejected\nMerge the remote changes (e.g. 'git pull') before pushing again.  See the\n'Note about fast-forwards' section of 'git push --help' for details.\n\nThe last time I encountered this, I did a \"get checkout master; git\nmerge origin/master; git checkout wpd; git push\" and that worked.  I\nhappen to know that master is a direct descendent of origin/master and\nthat, if I do this again, I will (once again) do a fast-forward merge\nto bring master up to origin/master.\n\nThis may have been fixed in a more recent git (I'm using git 1.7.2.5\non a Debian 6 box and 1.7.4.1 on an RHEL 5 box).\n\nThere has got to be an easier way to fix this than checking out the\nmaster branch, performing the fast-forward merge, and then switching\nback to my working branch.\n\nOne way would be if there were some way to do a fast-forward merge on\na branch without actually checking out that branch.  Hence my\nquestion.\n\nAnother way would be to remove the \"master\" branch from my config file.\n\nOr perhaps I set up something wrong.\n\n--wpd\n"},{"id":"171578","messageId":"4E244C75.6060407@viscovery.net","threadId":"27844","inReplyTo":"CAF_dkJCvtVqoDmRXMy23ZnZL6iUAVX0nNA9Ev6e4zvBp9mfTpg@mail.gmail.com","subject":"Re: How to do a fast-forward merge without a checkout?","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2011-07-18T15:08:37Z","receivedAt":"2011-07-18T15:08:37Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 7/18/2011 16:18, schrieb Patrick Doyle:\n> $ git push\n...\n> To somehost:path/to/repo\n>    e1004df..bad8767  wpd -> wpd\n>  ! [rejected]        master -> master (non-fast-forward)\n\n[Context: Patrick works on the topic branch, but can't push it anymore\nbecause the unrelated branch master was moved forward by someone else.]\n\nAfter the obligatory 'git fetch', there are at least two ways to do this:\n\n(1) The quick and unsafe way:\n\n    $ git branch -f master origin/master\n\n(2) The safer way:\n\n    $ git push . origin/master:master\n\nThe second command is safer because it checks that origin/master is indeed\na direct descendent of master.\n\n-- Hannes\n"},{"id":"171579","messageId":"CAF_dkJBWzOR76RUrB9P2UkLfR8_vhU-ExGROu73dAg=JJN-p_Q@mail.gmail.com","threadId":"27844","inReplyTo":"4E244C75.6060407@viscovery.net","subject":"Re: How to do a fast-forward merge without a checkout?","fromName":"Patrick Doyle","fromEmail":"wpdster@gmail.com","sentAt":"2011-07-18T15:25:46Z","receivedAt":"2011-07-18T15:25:46Z","isPatch":false,"sender":{"key":"wpdster@gmail.com","avatar":null},"body":"On Mon, Jul 18, 2011 at 11:08 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:\n> Am 7/18/2011 16:18, schrieb Patrick Doyle:\n>> $ git push\n> ...\n>> To somehost:path/to/repo\n>>    e1004df..bad8767  wpd -> wpd\n>>  ! [rejected]        master -> master (non-fast-forward)\n>\n> [Context: Patrick works on the topic branch, but can't push it anymore\n> because the unrelated branch master was moved forward by someone else.]\n>\n> After the obligatory 'git fetch', there are at least two ways to do this:\n>\n> (1) The quick and unsafe way:\n>\n>    $ git branch -f master origin/master\n>\n> (2) The safer way:\n>\n>    $ git push . origin/master:master\n>\n> The second command is safer because it checks that origin/master is indeed\n> a direct descendent of master.\n\nI like it!  (#2) It's obscure as all get-out, as UNIX commands were\nintended to be, does the job you need it to do in a manner that is\nintuitive, provided you understand what it's doing, and if you miss\nthe dot (perhaps, hypothetically speaking of course, because you\nthought it was a dust spec on your screen when you tried out the\ncommand), you get a very obscure error message (errr, hypothetically\nspeaking of course).\n\nSeriously... Thanks for the quick answers.  I'll tuck #2 into my bag\no' tricks.  In the mean time, I need to decide whether I really care\nabout my master branch or not.  I do care about origin/master, but I\ndo all my work on wpd and merge in changes from origin/master at\nrandom points in time.\n\nThanks again.\n\n--wpd\n"},{"id":"171582","messageId":"CACx-yZ1H5UfA9SeaGy-Ph+20BEsewJe7_78wQsr92Y09skSWHA@mail.gmail.com","threadId":"27844","inReplyTo":"CAF_dkJCvtVqoDmRXMy23ZnZL6iUAVX0nNA9Ev6e4zvBp9mfTpg@mail.gmail.com","subject":"Re: How to do a fast-forward merge without a checkout?","fromName":"knittl","fromEmail":"knittl89@googlemail.com","sentAt":"2011-07-18T16:08:16Z","receivedAt":"2011-07-18T16:08:16Z","isPatch":false,"sender":{"key":"knittl89@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/2149217?v=4"},"body":"On Mon, Jul 18, 2011 at 4:18 PM, Patrick Doyle <wpdster@gmail.com> wrote:\n> […]\n>\n> $ git push\n> […]\n> To somehost:path/to/repo\n>   e1004df..bad8767  wpd -> wpd\n>  ! [rejected]        master -> master (non-fast-forward)\n> error: failed to push some refs to 'somehost:path/to/repo'\n> To prevent you from losing history, non-fast-forward updates were rejected\n> Merge the remote changes (e.g. 'git pull') before pushing again.  See the\n> 'Note about fast-forwards' section of 'git push --help' for details.\n>\n\nanother way to avoid pushing the master branch is to explicitely name\nthe branch to push (wpd):\n\n    $ git push origin wpd\n\ncheers, daniel\n\n-- \ntyped with http://neo-layout.org\nmyFtPhp -- visit http://myftphp.sf.net -- v. 0.4.7 released!\n"},{"id":"171583","messageId":"CAF_dkJAx4mK26HcarMtRosy=MU8DgKx9aHWXXbTMK9kG=1LZWQ@mail.gmail.com","threadId":"27844","inReplyTo":"CACx-yZ1H5UfA9SeaGy-Ph+20BEsewJe7_78wQsr92Y09skSWHA@mail.gmail.com","subject":"Re: How to do a fast-forward merge without a checkout?","fromName":"Patrick Doyle","fromEmail":"wpdster@gmail.com","sentAt":"2011-07-18T16:13:46Z","receivedAt":"2011-07-18T16:13:46Z","isPatch":false,"sender":{"key":"wpdster@gmail.com","avatar":null},"body":"On Mon, Jul 18, 2011 at 12:08 PM, knittl <knittl89@googlemail.com> wrote:\n> On Mon, Jul 18, 2011 at 4:18 PM, Patrick Doyle <wpdster@gmail.com> wrote:\n>> […]\n>>\n>> $ git push\n>> […]\n>> To somehost:path/to/repo\n>>   e1004df..bad8767  wpd -> wpd\n>>  ! [rejected]        master -> master (non-fast-forward)\n>> error: failed to push some refs to 'somehost:path/to/repo'\n>> To prevent you from losing history, non-fast-forward updates were rejected\n>> Merge the remote changes (e.g. 'git pull') before pushing again.  See the\n>> 'Note about fast-forwards' section of 'git push --help' for details.\n>>\n>\n> another way to avoid pushing the master branch is to explicitely name\n> the branch to push (wpd):\n>\n>    $ git push origin wpd\n>\nThanks... I thought of that, but being basically lazy and not wanting\nto have to type all of those extra characters every time I did a \"git\npush\", I wanted to figure out a better way.\n\nSeth Milliken posted a great explanation and alternative solution in a\ncomment to a blog post I found at\nhttp://ken-blog.krugler.org/2010/02/25/git-failed-to-push-some-refs-the-multiple-branch-variant/.\n He suggested doing:\n\n$ git config remote.origin.push HEAD\n\nSo that \"git push\" would default to only pushing the current branch.\nI like that approach to my underlying problem as well.\n\nBut I stand in awe of Hanne's solution (#2) for it's brevity, the fact\nthat it does _exactly_ what I was asking about, and that the\ncapability is already baked into git.\n\n--wpd\n"},{"id":"171585","messageId":"CACx-yZ3_nZT61GXqE4uF5JRVekrqFKT4++spEKpL3vPdM8Nh8Q@mail.gmail.com","threadId":"27844","inReplyTo":"CAF_dkJAx4mK26HcarMtRosy=MU8DgKx9aHWXXbTMK9kG=1LZWQ@mail.gmail.com","subject":"Re: How to do a fast-forward merge without a checkout?","fromName":"knittl","fromEmail":"knittl89@googlemail.com","sentAt":"2011-07-18T16:24:37Z","receivedAt":"2011-07-18T16:24:37Z","isPatch":false,"sender":{"key":"knittl89@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/2149217?v=4"},"body":"On Mon, Jul 18, 2011 at 6:13 PM, Patrick Doyle <wpdster@gmail.com> wrote:\n> On Mon, Jul 18, 2011 at 12:08 PM, knittl <knittl89@googlemail.com> wrote:\n>> On Mon, Jul 18, 2011 at 4:18 PM, Patrick Doyle <wpdster@gmail.com> wrote:\n>>> […]\n>>>\n>>> $ git push\n>>> […]\n>>> To somehost:path/to/repo\n>>>   e1004df..bad8767  wpd -> wpd\n>>>  ! [rejected]        master -> master (non-fast-forward)\n>>> error: failed to push some refs to 'somehost:path/to/repo'\n>>> To prevent you from losing history, non-fast-forward updates were rejected\n>>> Merge the remote changes (e.g. 'git pull') before pushing again.  See the\n>>> 'Note about fast-forwards' section of 'git push --help' for details.\n>>>\n>>\n>> another way to avoid pushing the master branch is to explicitely name\n>> the branch to push (wpd):\n>>\n>>    $ git push origin wpd\n>>\n> Thanks... I thought of that, but being basically lazy and not wanting\n> to have to type all of those extra characters every time I did a \"git\n> push\", I wanted to figure out a better way.\n\nI can understand your laziness ;)\n\n> Seth Milliken posted a great explanation and alternative solution in a\n> comment to a blog post I found at\n> http://ken-blog.krugler.org/2010/02/25/git-failed-to-push-some-refs-the-multiple-branch-variant/.\n>  He suggested doing:\n>\n> $ git config remote.origin.push HEAD\n>\n> So that \"git push\" would default to only pushing the current branch.\n> I like that approach to my underlying problem as well.\n\nI prefer to use\n\n    $ git config --global push.default current\n\nwhich tells git to push the current branch to a branch of the same\nname (for every repository). Another possible (and useful) value is\n\"upstream\"/\"tracking\": push the current branch to it's upstream. Have\na look at the git config manpage for more options.\n\n> But I stand in awe of Hanne's solution (#2) for it's brevity, the fact\n> that it does _exactly_ what I was asking about, and that the\n> capability is already baked into git.\n\nYup, pushing into the current repository to fast-forward branches\nwithout checkout is quite neat indeed :)\n\nDaniel\n\n-- \ntyped with http://neo-layout.org\nmyFtPhp -- visit http://myftphp.sf.net -- v. 0.4.7 released!\n"}]}