当我新建了一个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
发现还是报错,报错内容文章来源:https://www.toymoban.com/news/detail-589424.html
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模板网!