我昨天还能推,现在却推不动了。

当我使用git push origin master时,我得到一个错误:

$ git remote -v
origin  https://github.com/REDACTED.git (fetch)
origin  https://github.com/REDACTED.git (push)

$ git push origin master
Username for 'https://github.com': REDACTED
Password for 'https://REDACTED@github.com':
To https://github.com/REDACTED.git
! [rejected]         master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/REDACTED.git'
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.

我的工作目录和远程存储库看起来像什么:


当前回答

试着用

git status

你的分支是基于“origin/main”的,但是上游已经没有了。

然后执行以下步骤

git branch --unset-upstream
git push --set-upstream origin main

其他回答

在我们的例子中,重新尝试push解决了问题。可能是网络速度慢导致了这个问题。

试试这个Git命令,

git push origin master –f
git push origin master --force

检查一下你的网络连接是否正常,速度是否快。

我试图用我的4G移动热点推送,但在近10分钟内出现了这个错误。

附注:在印度,我们的4G网络只有3G速度,所以在做一些花哨的事情之前;看看是否有合理的速度可用:)

试着用

git status

你的分支是基于“origin/main”的,但是上游已经没有了。

然后执行以下步骤

git branch --unset-upstream
git push --set-upstream origin main

我在GitHub中创建了一个空的存储库,并在本地有我的代码。我现在面临着同样的问题,我按照下面的顺序,

git init
git commit -m 'Initial Commit'
git remote add origin https://github.com/kavinraju/Repo-Name.git
git add .
git push -u origin master

问题是:我试图在暂存我拥有的文件之前提交。

所以我们需要暂存文件,然后提交。

这是正确的顺序。

git init
git add .
git commit -m 'Initial Commit'
git remote add origin https://github.com/kavinraju/Repo-Name.git
git push -u origin master

因为我首先执行了错误的序列,所以我只执行了下面的命令:

git add .
git commit -m 'Initial Commit'
git push -u origin master