【问题标题】:I can't push my code and keep getting the same error no matter what I do无论我做什么,我都无法推送我的代码并不断收到相同的错误
【发布时间】:2019-06-21 00:18:32
【问题描述】:

我正在尝试将我的代码推送到我的远程分支,但一直收到此错误:

! [rejected] (non-fast-forward)
error: failed to push some refs to 'git@github.com:
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

我认为导致这种情况的原因可能是我在 github 上而不是通过本地环境修复了我的 README.md 中的错字。

我查看了所有堆栈溢出并尝试了他们针对此问题提到的命令,例如 git pullgit pull --rebasegit pull origin mastergit push --f 和许多其他命令都无济于事。

我也尝试了以下问题的答案,但没有成功:

Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g [duplicate]

Cannot push to GitHub - keeps saying need merge

Git pull a certain branch from GitHub

我也试过git pull upstream master,但我得到了这个错误:

fatal: 'upstream' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

【问题讨论】:

标签: git github git-push


【解决方案1】:

问题已解决:

我添加了另一个更改并将其保存在我的本地环境中并执行了以下操作:

git stash

git pull origin <branch-name> -v

git add .

git commit

git push origin <branch-name>

【讨论】:

    【解决方案2】:

    根据您的描述,我假设您位于从master 派生的不同分支上,并且master 设置为跟踪origin/master

    尝试先切换回它:

    git checkout master
    git fetch
    git pull origin master
    

    您可能必须合并您的更改,因为远程上有一个新的提交,并且您也有一些新的东西。

    【讨论】:

      【解决方案3】:

      首先使用命令备份您的代码:git stash

      然后使用命令git pullgit pull upstream master,如果你有任何上游集(我假设你有)。

      将更改从 master 合并到本地 Git 合并上游/master。

      git push
      

      现在,如果您在浏览器中打开您的分支,您将看到“您的分支与 master 同步”的消息。 ** 它应该始终保持同步。 **

      现在使用命令git stash pop 取回您的更改并提交。

      【讨论】:

      • 感谢@Josh Abraham 的编辑。我用手机发布了答案。
      猜你喜欢
      • 2021-03-08
      • 2016-07-14
      • 2015-08-25
      • 2016-10-30
      • 2019-09-06
      • 2012-10-22
      • 2023-01-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多