Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git --amend --no-edit rejected push

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://[email protected]/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.

like image 869
Emaborsa Avatar asked Oct 19 '25 13:10

Emaborsa


1 Answers

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.

like image 117
talshorer Avatar answered Oct 22 '25 02:10

talshorer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!