{"thread":{"id":"38047","subject":"push rejected (non-fast-forward)","startedAt":"2014-11-25T17:45:45Z","lastAt":"2014-11-26T00:16:11Z","messageCount":3,"participants":["debugging data","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"252527","messageId":"C2E11014-CFE8-490E-A21A-DB42CC8E4175@gmail.com","threadId":"38047","inReplyTo":null,"subject":"push rejected (non-fast-forward)","fromName":"debugging data","fromEmail":"debugging.data@gmail.com","sentAt":"2014-11-25T17:45:45Z","receivedAt":"2014-11-25T17:45:45Z","isPatch":false,"sender":{"key":"debugging.data@gmail.com","avatar":null},"body":"Changes to a remote branch causes a user not to be able to push their\nchanges because their tip is behind its remote counterpart.\n\n\nHere are the git repos:\n\ngithub.com/user-one/project\ngithub.com/user-two/project\n\nHere's what happened:\n\n1. user-one creates a project and adds file-one.txt to the repo with\ncontents \"file one\"\n\n2. user-one commits and pushes to master\n\n3. user-one creates directory \"foo/\" with a file named \"foo.txt\". \"foo.txt\"\ncontains text \"foo\"\n\n4. user-one commits and pushes to master\n\n5. user-two forks github.com/user-one/project\n\n6. user-two creates new branch called \"so-much-foo\" and changes the text of\nfoo/foo.txt to \"so much foo\"\n\n7. user-two commit, pushes, to origin/master, and creates a pull request\n\n8. user-one creates \"file-two.txt\" with contents \"file two\", commits, and\npushes to master\n\n9. user-two changes the contents of \"foo/foo.txt\" from \"so much foo\" to\n\"foo\\nfoo\", then commits the file\n\n10. user-two types this command: `git remote add user-one git@github.com:\nuser-one/project.git`\n\n11. user-two types another command: git pull --rebase user-one master\n\n12. user-two attempts to push changes to the branch so-much-foo but is\ndenied as seen here:\n\n$ git push origin so-much-foo\nTo git@github.com:user-two/project.git\n ! [rejected]        so-much-foo -> so-much-foo (non-fast-forward)\nerror: failed to push some refs to 'git@github.com:user-two/project.git'\nhint: Updates were rejected because the tip of your current branch is behind\nhint: its remote counterpart. Integrate the remote changes (e.g.\nhint: 'git pull ...') before pushing again.\n\n\nIt doesn't look like the tip is behind though:\n\n\n/project$ git log\ncommit dd240b6ba15d27d074726e9b1b0e665e3507a2fd\nAuthor: User Two <debugging.data+user2@gmail.com>\nDate:   Mon Nov 24 22:55:45 2014 +0000\n\n    foo/foo.txt from \"so much foo\" to \"foo\\nfoo\"\n\ncommit 5cd55b8775750c2631b3c1f249f541402cc38c27\nAuthor: User Two <debugging.data+user2@gmail.com>\nDate:   Mon Nov 24 22:51:12 2014 +0000\n\n    changed foo/foo.txt contents to \"so much foo\"\n\ncommit 75fca5dfa5157a18b55bb89fba70aee8680cfbf2\nAuthor: User One <debugging.data+user1@gmail.com>\nDate:   Mon Nov 24 22:52:42 2014 +0000\n\n    file-two.txt with contents \"file two\"\n\ncommit faf9ccfbde95158b2b4a3e291a1e32789381a37e\nAuthor: User One <debugging.data+user1@gmail.com>\nDate:   Mon Nov 24 22:46:28 2014 +0000\n\n    foo/ and foo/foo.txt with contents \"foo\"\n\ncommit 17471484163127daaf5233eccf5fac89e9d7a53e\nAuthor: User One <debugging.data+user1@gmail.com>\nDate:   Mon Nov 24 22:43:08 2014 +0000\n\n    file-one.txt with contents \"file one\"\n\n\nI have struggled with this today, and I'm not sure what to do, so I've\nresorted to asking for help here. I guess someone here has dealt with this\nat least once.\n\nAre there tools that would help make this process easier?\n"},{"id":"252537","messageId":"xmqqsih7rsyu.fsf@gitster.dls.corp.google.com","threadId":"38047","inReplyTo":"C2E11014-CFE8-490E-A21A-DB42CC8E4175@gmail.com","subject":"Re: push rejected (non-fast-forward)","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-11-25T19:16:41Z","receivedAt":"2014-11-25T19:16:41Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"debugging data <debugging.data@gmail.com> writes:\n\n> $ git push origin so-much-foo\n> To git@github.com:user-two/project.git\n>  ! [rejected]        so-much-foo -> so-much-foo (non-fast-forward)\n> error: failed to push some refs to 'git@github.com:user-two/project.git'\n> hint: Updates were rejected because the tip of your current branch is behind\n> hint: its remote counterpart. Integrate the remote changes (e.g.\n> hint: 'git pull ...') before pushing again.\n>\n>\n> It doesn't look like the tip is behind though:\n>\n>\n> /project$ git log\n> commit dd240b6ba15d27d074726e9b1b0e665e3507a2fd\n> Author: User Two <debugging.data+user2@gmail.com>\n> ...\n> Date:   Mon Nov 24 22:43:08 2014 +0000\n>\n>     file-one.txt with contents \"file one\"\n\nI do not think anybody can say \"It doesn't look like the tip is\nbehind\" by looking only at the above.  I am assuming that you are on\nyour \"so-much-foo\" branch, but that shows only your state.  You are\nnot inspecting what is actually on the remote branch you are pushing\nto, so...\n\nAfter the failed \"git push origin so-much-foo\", try \"git fetch\norigin so-much-foo\", which will make the tip of the so-much-foo\nbranch over there temporarily available in your FETCH_HEAD.  And\nthen do something like:\n\n    $ git show-branch FETCH_HEAD so-much-foo\n\nand see how they have diverged.  If you want to merge your work with\nthe updated origin, you can do\n\n    $ git merge FETCH_HEAD\n\nafter that, or follow the hint given by the failed push, i.e.\n\n> hint: its remote counterpart. Integrate the remote changes (e.g.\n> hint: 'git pull ...') before pushing again.\n\nand do\n\n    $ git pull origin so-much-foo\n\n(which by the way can be done without the \"git fetch origin ...\"\nand \"git show-branch ...\" steps above).\n"},{"id":"252553","messageId":"443C531A-FD94-40F2-B661-209F6327A1A0@gmail.com","threadId":"38047","inReplyTo":"xmqqsih7rsyu.fsf@gitster.dls.corp.google.com","subject":"Re: push rejected (non-fast-forward)","fromName":"debugging data","fromEmail":"debugging.data@gmail.com","sentAt":"2014-11-26T00:16:11Z","receivedAt":"2014-11-26T00:16:11Z","isPatch":false,"sender":{"key":"debugging.data@gmail.com","avatar":null},"body":"Thank you Junio.\n\nDo you know how the\n\n    $ git pull origin so-much-foo` \n\ncommand manages to keep user-two’s branch up-to-date with remote?\n\nIt seems counterintuitive since I am pulling from origin and not explicitly working with remote.\n \nWould what you see here been an acceptable scenario?\nhttps://github.com/user-one/project/pull/1\n\nI performed a `git pull` and merged the changes manually. This looks like an awful lot to keep track of, and I’m not sure if it’s acceptable for larger projects.\n\nMy goal here is to prepare myself to help out with a large open source project.\n\nAlso, if anyone has the patience, would you mind explaining what’s going on here?\n\n$ git show-branch FETCH_HEAD so-much-foo\n! [FETCH_HEAD] changed foo/foo.txt contents to \"so much foo\"\n * [so-much-foo] foo/foo.txt from \"so much foo\" to \"foo\\nfoo\"\n"}]}