无论我做什么,我都无法推送我的代码并不断收到相同的错误

Mei*_*kay 5 git github git-push

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

! [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
Run Code Online (Sandbox Code Playgroud)

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

我已经查看了堆栈溢出并尝试了他们针对此问题提到的命令,例如git pull, git pull --rebase, git pull origin master,git push --f和许多其他与无济于事。

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

更新被拒绝,因为您当前分支的提示在提示后面:它的远程副本。集成远程更改(例如 [重复]

无法推送到 GitHub - 一直说需要合并

Git 从 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.
Run Code Online (Sandbox Code Playgroud)

Kun*_*hra 0

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

\n\n

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

\n\n

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

\n\n
git push\n
Run Code Online (Sandbox Code Playgroud)\n\n

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

\n\n

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

\n