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

 

修改时间 2024-05-12

声明:本站所有文章和图片,如无特殊说明,均为原创发布,转载请注明出处。
随机推荐
Node.js 内置模块
JavaScript EventSource 服务器发送事件 Server-Sent Events(SSE)
Node.js os 模块
Page Visibility API
WordPress 引入自定义 JavaScript 文件
JavaScript 修改 CSS 样式
Express 使用模板引擎 EJS
JavaScript DOM 查找元素