首页 > 解决方案 > 将本地文件中的更新推送到 github 存储库时出错

问题描述

我在本地对项目的一些 HTML 文件进行了一些更改,并尝试使用 Git Bash 将更改推送到我的 github 存储库中。但它显示以下错误

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

我已经从 Github 更改了存储库的名称,但随后使用命令在 Git Bash 上对其进行了更新

 git remote set-url origin https://github.com/cyborg7459/bambinos-task1

如何解决这个问题?

标签: gitgithubrepositorygit-bash

解决方案


这里的问题是远程存储库正在更新其他用户的提交,而这些提交在您的本地不可用。因此,为了将本地更改推送到远程,您可以做的是首先将更改从上游拉到本地,解决合并冲突(如果有)并提交,然后最后推送。

从上游拉取/获取最新更改

git pull origin <branch>

推送更改

git push origin <branch>

注意 在某些情况下,拉取后可能会出现合并冲突,那么您必须在本地解决问题。暂存并提交更改。

git add .
git commit -m <commit message>
git push origin <branch>

推荐阅读