4

Today I discovered the --no-edit for the --amend. However, it leads me to the following problem. Here the steps:

  • git clone
  • did some changes to the code
  • git add .
  • git commit --amend --no-edit
  • git push origin master

    ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to 'https://me@bitbucket.org/myRepo.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.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    

Why?

Note: I'm the only one which works on that repo.

Emaborsa
  • 2,360
  • 4
  • 28
  • 50
  • Just a stupid question, have you pulled before trying to push (as the hint suggests) ? – Joseph Budin Mar 05 '18 at 15:43
  • I have just checked out, It cannot be behind – Emaborsa Mar 05 '18 at 15:45
  • When you do `git fetch origin`, does anything come in for the `origin/master` tracking branch? – Tim Biegeleisen Mar 05 '18 at 15:47
  • 1
    No nothing, but why should I fetch if I just checked out? – Emaborsa Mar 05 '18 at 15:48
  • I'm trying to see if there are any commits on the remote `master` which you don't know about. If there _aren't_, then I'm at a loss as to the error message. – Tim Biegeleisen Mar 05 '18 at 15:49
  • 1
    Possible duplicate of [git: "Updates were rejected because the tip of your current branch is behind.." but how to see differences?](https://stackoverflow.com/questions/45293263/git-updates-were-rejected-because-the-tip-of-your-current-branch-is-behind) – phd Mar 05 '18 at 15:55
  • not a duplicate, may have the same error message but the underlying question is different. – Mad G Jul 31 '18 at 09:14

1 Answers1

9

Amending the last commit rewrites history. If that's what you want to do, you can do that with git push --force.

The reason it tells you you're behind is because the last commit that exists both locally and remotely (aka "merge base") is the tip's parent. In that regard, you're one commit behind the remote, which already has a commit on top of the aforementioned merge base.

talshorer
  • 662
  • 3
  • 9