解决gitpush时报错:hint: Updates were rejected because the remote contains work that you do hint: not have

这篇具有很好参考价值的文章主要介绍了解决gitpush时报错:hint: Updates were rejected because the remote contains work that you do hint: not have。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

当我新建了一个git仓库,依次执行

git add .
git commit -m 'create a new project'
git remote add  webbrowser https://gitee.com/caimingz/webbrowser.git
git push -u webbrowser master

却报错

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/caimingz/webbrowser.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first 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.

报这个错是因为远程仓库和本地仓库文件不同步,解决方法是先执行git pull将远程仓库文件拉下来使得远程与本地同步。
解决步骤

1.执行

git pull  webbrowser  master --allow-unrelated-histories

这里的webbrowser换成你的远程仓库名
执行后会有如下输出

remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), 4.99 KiB | 16.00 KiB/s, done.
From https://gitee.com/caimingz/webbrowser
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> webbrowser/master
CONFLICT (add/add): Merge conflict in .gitignore
Auto-merging .gitignore
Automatic merge failed; fix conflicts and then commit the result.

2.再试试重新推送行不行

git push -u webbrowser master

发现还是报错,报错内容

error: failed to push some refs to 'https://gitee.com/caimingz/webbrowser.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 pull之后需要 走一遍提交步骤文章来源地址https://www.toymoban.com/news/detail-589424.html

1. git add -u 
2. git commit -m 'update'
3.  git pull   webbrowser master --allow-unrelated-histories
4. git push -u webbrowser master

到了这里,关于解决gitpush时报错:hint: Updates were rejected because the remote contains work that you do hint: not have的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包