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

当我使用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 push origin master,请将其更改为git push origin main,反之亦然。

其他回答

如果您正在使用Gerrit,这可能是由提交中不适当的Change-id引起的。尝试删除Change-Id,看看会发生什么。

我尝试了'git push origin main',然后收到了消息。然后我尝试单独使用“git push”,但它不起作用。

我检查了一下我是否承诺了(是的)。我试着“拉”,然后“推”,但没有。

在开始一些特技之前,我只是关闭并打开一个新的终端,然后再次“推”,它工作了:p

在我的例子中,我把分行的名字拼错了。在当地,我做了这样的事情:

Git push——set-upstream origin feature /my-feature

我的分支名称缺少a in特性。我把它更正为:

Git push——set-upstream origin feature/my-feature

一切都很顺利。

如果你刚刚使用git init并添加了git add文件。或者类似的东西,并且添加了远程分支,它可能是你还没有在本地提交(git commit -m 'commit message')任何东西来推送到远程…我只是有这个错误,这是我的问题。

对于Sourcetree用户

首先进行初始提交,或者确保没有任何未提交的更改。然后在Sourcetree的一侧有一个“REMOTES”。右键单击它,然后单击“推到原点”。好了。