I have forked a github repository and by now my fork is several commits ahead. I now want to provide one of these commits as a PR to the original repository.
Following this question's answer, I did:
git remote add official [URL to original repo]
git checkout -b hotfix-for-feature official/master
git cherry-pick [feature-hash]
git push -u origin hotfix-for-feature
and I get:
! [rejected] hotfix-for-feature -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/myusername/repositoryname'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Note how:
- The branch argument to
git push -uis just completely ignored and it wants to push to origin/master - Neither
origin/hotfix-for-featurenorofficial/hotfix-for-featureexist remotely. official/masteris not ahead in any way - I literally just fetched it
If I try git branch hotfix-for-feature --set-upstream=origin/hotfix-for-feature I'm told that git push -u is the proper way to do this. If I try git push -u origin/hotfix-for-feature I get:
fatal: You are pushing to remote 'origin/hotfix-for-feature',
which is not the upstream of your current branch 'hotfix-for-feature',
without telling me what to push to update which remote branch.
which - apart from being a good example of how not to write your error messages - I don't understand. I specify what to push (current branch) and which remote branch to update.
I find lots of questions about this error, but it is always about some remote branch being ahead and in this case there is no existing remote branch. Also what is the difference between a "pushed branch" and a "remote [branch]"?