doubleyong
管理员
管理员
  • 最后登录2025-03-16
  • 发帖数1196
  • 最爱沙发
  • 喜欢达人
  • 原创写手
  • 社区居民
  • 忠实会员
阅读:6583回复:0

[其它]【git】解决办法:error: failed to push some refs to 'https://github.com/xxxx.git'

楼主#
更多 发布于:2020-08-03 10:51

问题描述:在github远程创建仓库后, 利用gitbash进行提交本地文件的时候出现如下错误

doubleyong@DESKTOP-M7I4UJU MINGW64 /e/guoxinan/2020/project/demo3_react_roleManage (master)
$ git push -u origin master
To https://github.com/doubleyong/react_role_normal.git
! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/doubleyong/react_role_normal.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.


问题分析:我是先在github上创建了空仓库, 当时勾选了创建readme.md文件, 但是在利用gitbash的时候没有pull到本地.之后利用gitbash进行提交本地文件到仓库, 在push的时候出现错误.

解决办法:错误信息中可以看出本地和远程匹配不完整, 在网上也查找了下, 总结为本地仓库和远程仓库有冲突所致 .总结的几种解决办法:
1: 进行push前先将远程仓库pull到本地仓库
$ git pull origin master    #git pull --rebase origin master
$ git push -u origin master

2: 强制push本地仓库到远程 (这种情况不会进行merge, 强制push后远程文件可能会丢失 不建议使用此方法)

$ git push -u origin master -f
3: 避开解决冲突, 将本地文件暂时提交到远程新建的分支中

$ git branch [name]
# 创建完branch后, 再进行push
$ git push -u origin [name]


转自:https://blog.csdn.net/dietime1943/article/details/79398771
知识需要管理,知识需要分享
游客


返回顶部

公众号

公众号