# push rejected (non-fast-forward)

3 messages from 2014-11-25 to 2014-11-26. Participants: debugging data, Junio C Hamano.
Thread: https://gitlist.dev/t/38047

## debugging data, 2014-11-25 17:45

Subject: push rejected (non-fast-forward)
Message-ID: <C2E11014-CFE8-490E-A21A-DB42CC8E4175@gmail.com>
URL: https://gitlist.dev/e/C2E11014-CFE8-490E-A21A-DB42CC8E4175%40gmail.com

```
Changes to a remote branch causes a user not to be able to push their
changes because their tip is behind its remote counterpart.


Here are the git repos:

github.com/user-one/project
github.com/user-two/project

Here's what happened:

1. user-one creates a project and adds file-one.txt to the repo with
contents "file one"

2. user-one commits and pushes to master

3. user-one creates directory "foo/" with a file named "foo.txt". "foo.txt"
contains text "foo"

4. user-one commits and pushes to master

5. user-two forks github.com/user-one/project

6. user-two creates new branch called "so-much-foo" and changes the text of
foo/foo.txt to "so much foo"

7. user-two commit, pushes, to origin/master, and creates a pull request

8. user-one creates "file-two.txt" with contents "file two", commits, and
pushes to master

9. user-two changes the contents of "foo/foo.txt" from "so much foo" to
"foo\nfoo", then commits the file

10. user-two types this command: `git remote add user-one git@github.com:
user-one/project.git`

11. user-two types another command: git pull --rebase user-one master

12. user-two attempts to push changes to the branch so-much-foo but is
denied as seen here:

$ git push origin so-much-foo
To git@github.com:user-two/project.git
 ! [rejected]        so-much-foo -> so-much-foo (non-fast-forward)
error: failed to push some refs to 'git@github.com:user-two/project.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.


It doesn't look like the tip is behind though:


/project$ git log
commit dd240b6ba15d27d074726e9b1b0e665e3507a2fd
Author: User Two <debugging.data+user2@gmail.com>
Date:   Mon Nov 24 22:55:45 2014 +0000

    foo/foo.txt from "so much foo" to "foo\nfoo"

commit 5cd55b8775750c2631b3c1f249f541402cc38c27
Author: User Two <debugging.data+user2@gmail.com>
Date:   Mon Nov 24 22:51:12 2014 +0000

    changed foo/foo.txt contents to "so much foo"

commit 75fca5dfa5157a18b55bb89fba70aee8680cfbf2
Author: User One <debugging.data+user1@gmail.com>
Date:   Mon Nov 24 22:52:42 2014 +0000

    file-two.txt with contents "file two"

commit faf9ccfbde95158b2b4a3e291a1e32789381a37e
Author: User One <debugging.data+user1@gmail.com>
Date:   Mon Nov 24 22:46:28 2014 +0000

    foo/ and foo/foo.txt with contents "foo"

commit 17471484163127daaf5233eccf5fac89e9d7a53e
Author: User One <debugging.data+user1@gmail.com>
Date:   Mon Nov 24 22:43:08 2014 +0000

    file-one.txt with contents "file one"


I have struggled with this today, and I'm not sure what to do, so I've
resorted to asking for help here. I guess someone here has dealt with this
at least once.

Are there tools that would help make this process easier?

```

## Junio C Hamano, 2014-11-25 19:16

Subject: Re: push rejected (non-fast-forward)
Message-ID: <xmqqsih7rsyu.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqqsih7rsyu.fsf%40gitster.dls.corp.google.com
In-Reply-To: <C2E11014-CFE8-490E-A21A-DB42CC8E4175@gmail.com>

```
debugging data <debugging.data@gmail.com> writes:

> $ git push origin so-much-foo
> To git@github.com:user-two/project.git
>  ! [rejected]        so-much-foo -> so-much-foo (non-fast-forward)
> error: failed to push some refs to 'git@github.com:user-two/project.git'
> hint: Updates were rejected because the tip of your current branch is behind
> hint: its remote counterpart. Integrate the remote changes (e.g.
> hint: 'git pull ...') before pushing again.
>
>
> It doesn't look like the tip is behind though:
>
>
> /project$ git log
> commit dd240b6ba15d27d074726e9b1b0e665e3507a2fd
> Author: User Two <debugging.data+user2@gmail.com>
> ...
> Date:   Mon Nov 24 22:43:08 2014 +0000
>
>     file-one.txt with contents "file one"

I do not think anybody can say "It doesn't look like the tip is
behind" by looking only at the above.  I am assuming that you are on
your "so-much-foo" branch, but that shows only your state.  You are
not inspecting what is actually on the remote branch you are pushing
to, so...

After the failed "git push origin so-much-foo", try "git fetch
origin so-much-foo", which will make the tip of the so-much-foo
branch over there temporarily available in your FETCH_HEAD.  And
then do something like:

    $ git show-branch FETCH_HEAD so-much-foo

and see how they have diverged.  If you want to merge your work with
the updated origin, you can do

    $ git merge FETCH_HEAD

after that, or follow the hint given by the failed push, i.e.

> hint: its remote counterpart. Integrate the remote changes (e.g.
> hint: 'git pull ...') before pushing again.

and do

    $ git pull origin so-much-foo

(which by the way can be done without the "git fetch origin ..."
and "git show-branch ..." steps above).

```

## debugging data, 2014-11-26 00:16

Subject: Re: push rejected (non-fast-forward)
Message-ID: <443C531A-FD94-40F2-B661-209F6327A1A0@gmail.com>
URL: https://gitlist.dev/e/443C531A-FD94-40F2-B661-209F6327A1A0%40gmail.com
In-Reply-To: <xmqqsih7rsyu.fsf@gitster.dls.corp.google.com>

```
Thank you Junio.

Do you know how the

    $ git pull origin so-much-foo` 

command manages to keep user-two’s branch up-to-date with remote?

It seems counterintuitive since I am pulling from origin and not explicitly working with remote.
 
Would what you see here been an acceptable scenario?
https://github.com/user-one/project/pull/1

I 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.

My goal here is to prepare myself to help out with a large open source project.

Also, if anyone has the patience, would you mind explaining what’s going on here?

$ git show-branch FETCH_HEAD so-much-foo
! [FETCH_HEAD] changed foo/foo.txt contents to "so much foo"
 * [so-much-foo] foo/foo.txt from "so much foo" to "foo\nfoo"

```
