0

Made a pull request, then made a few extra commits inadvertently and cannot return to the first commit in the branch.

What i do:

git reset HEAD@{10}
git add .
git commit --amend --no-edit
git push origin areaSelection

Error:

To https://github.com/YaroshenkoYaroslav/WorldEdit.git
 ! [rejected]        areaSelection -> areaSelection (non-fast-forward)
error: failed to push some refs to 'https://github.com/YaroshenkoYaroslav/WorldEdit.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.

How can i fix this?

  • https://stackoverflow.com/search?q=%5Bgit%5D+hint%3A+Updates+were+rejected+because+the+tip+of+your+current+branch+is+behind – phd Apr 21 '20 at 13:23

1 Answers1

1

You have two options, and that probably just depends on conventions in your team or restrictions on your github repository.

  1. What is pushed should not change; so just create a new commit on top of your remote branch and push that.
  2. You really want to rewrite the history of your branch. This means that some references that were pushed before will disappear (the commits that you remove). In that case you need to force things: git push --force-with-lease.
Chris Maes
  • 35,025
  • 12
  • 111
  • 136
  • I get the error : "fatal: The current branch areaSelection has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin areaSelection" – Yaroshenko Yaroslav Apr 21 '20 at 12:50
  • you can do that. This "links" your local branch "areaSelection" to its upstream counterpart "origin/areaSelection". – Chris Maes Apr 21 '20 at 12:58
  • All the same error "To https://github.com/YaroshenkoYaroslav/WorldEdit.git ! [rejected] areaSelection -> areaSelection (non-fast-forward) error: failed to push some refs to 'https://github.com/YaroshenkoYaroslav/WorldEdit.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote..." – Yaroshenko Yaroslav Apr 21 '20 at 13:10
  • 1
    yes you need to combine both now: `git push -u origin --force-with-lease areaSelection` (-u = shorthand for --set-upstream) – Chris Maes Apr 21 '20 at 13:12
  • Thanks a lot, you are the best. Really helped out – Yaroshenko Yaroslav Apr 21 '20 at 13:17