简体   繁体   中英

Pushing a master branch to github repository after reset

So basically for whatever reason after merging my master branch with another branch and pushing master branch to github repo my code was filled with <<<<<<< HEAD for whatever reason, even in places that I edited many commits ago so what I did was git reset --hard to the previous commit and that fixed the code now when I try to push my master branch to github repo I get

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'my github repo'
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.

now doing git pull would just give me the code that's filled <<<<<<HEAD which I don't need. So I looked for some solutions and the first few results suggested git push -f origin branch but when I do that I get

error: src refspec branch does not match any.
error: failed to push some refs to my github repo

so what should I do now, lads?

git push github master
To git@github.com:Joey-project/project.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:Joey-project/project.git'

is an often reoccuring error.

I've read that one of the solutions is to use a variation of the following commands:

git fetch github; git merge github/master

May I suggest you to also look at Git non-fast-forward updates were rejected Merge the remote changes , it has a lot of extra information..

found it myself

git push origin HEAD --force

does the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM