git上传出现! [rejected] master -> master (non-fast-forward) 错误

 

输入:

git push -u origin master

产生错误:

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

 

原因:git仓库中已经有一部分代码存在,所以不允许直接把你的代码push上去而覆盖掉原来的代码

 

 

解决方法一:同步git内容到本地,再push上去

git fetch
git merge origin FETCH_HEAD

再执行git push命令

 

解决方法二:强制上传,这样回覆盖掉git仓库上原有的代码

git push -f

 

posted @ 2022-08-20 12:12  Makerr  阅读(493)  评论(0编辑  收藏  举报