Git push 错误:Updates were rejected because the remote contains work that you do not have locally

执行 git push -u origin main 报错:

git push -u origin main
To https://gitee.com/test/test.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://gitee.com/soushenji/expressjs-docs.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.


由于远程包含本地没有的工作,更新被拒绝。这通常是由另一个存储库推送到同一个ref引起的。所以应该提前执行 git pull 一下。

执行一下 git pull origin main --allow-unrelated-histories 即可。


如果你确信你的更改与远程仓库中的更改不会有冲突,你可以使用强制推送,但这种做法通常不推荐,因为它会覆盖远程仓库中的提交:

git push origin master --force


声明:本站所有文章和图片,如无特殊说明,均为原创发布。商业转载请联系作者获得授权,非商业转载请注明出处。
真诚赞赏,手留余香
赞赏
随机推荐
WordPress关闭自动草稿
WP_REST_Response 返回结果类
MySQL 删除逗号分隔字段中的某一个值
WordPress 自定义 JWT 授权和验证
p 标签里面不能嵌套块级元素
Flame 插件
HTML 对话框元素 dialog
PHP curl 的用法