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

当我使用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 main',然后收到了消息。然后我尝试单独使用“git push”,但它不起作用。

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

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

其他回答

在我的例子中,分支名称前缀已经存在于远程,所以基本上,如果你有一个分支名称“fix”,你不能推送另一个名称为“fix/new_branch_name”的分支。

重命名分支解决了我的问题。

你需要给点力

用力推就行。

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

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

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

对于Sourcetree用户

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

我按照下面的步骤,它对我很有效。

 rm -rf .git
 git init
 git add .
 git commit -m"first message"
 git remote add origin "LINK"
 git push -u origin master