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?

1

1 Answer 1

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.
5
  • 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" Commented Apr 21, 2020 at 12:50
  • you can do that. This "links" your local branch "areaSelection" to its upstream counterpart "origin/areaSelection".
    – Chris Maes
    Commented Apr 21, 2020 at 12:58
  • All the same error "To github.com/YaroshenkoYaroslav/WorldEdit.git ! [rejected] areaSelection -> areaSelection (non-fast-forward) error: failed to push some refs to 'github.com/YaroshenkoYaroslav/WorldEdit.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote..." Commented Apr 21, 2020 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
    Commented Apr 21, 2020 at 13:12
  • Thanks a lot, you are the best. Really helped out Commented Apr 21, 2020 at 13:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.