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

当我使用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.

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


当前回答

我得到了这个错误,因为我试图在没有提交的情况下进行push 所以试着

Git添加。 Git commit -m "message" Git push -f

然后它对我很有效

其他回答

你需要给点力

用力推就行。

我不确定这是否适用,但对我来说,修复是在git初始化后在本地提交一些东西。然后我使用——set-upstream推到远程。

创建一个新的分支为我解决了这个问题:

git checkout -b <nameOfNewBranch>

正如预期的那样,不需要合并,因为前一个分支完全包含在新分支中。

在push之前,你必须添加并提交更改,或者执行git push -f origin master。

GitHub将默认分支名从master改为main。因此,如果您最近创建了回购,请尝试推主分支。

git push origin main

这是初学者容易犯的错误。

从master重命名默认分支。