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

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

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


当前回答

如果您是第一次在GitHub页面上部署站点,只需运行这两个命令。

git commit -m "initial commit"
git push origin +HEAD

其他回答

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

git checkout -b <nameOfNewBranch>

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

我正在推动一个带有拼写错误“develop”的现有分支,我还没有签出它,相反,我想推动一个名为“envelope”的分支。

因此,分支必须存在,并在本地工作副本上签出,以便能够推送。因此,解决这个错误的方法是不要出现错别字。

我也有同样的问题。我遇到这个问题是因为我没有做出任何承诺,甚至没有最初的承诺,但我仍然试图推动。

一旦我真的commit -m“your msg”,一切都很正常。

当您没有任何文件时,可能会发生这种情况。 尝试创建一个文本文件,然后执行以下命令:

git add .
git commit -m "first commit"
git push --set-upstream origin master

当远程服务器有一些额外的提交时,这个问题就会出现在你的工作目录中。下面是修复此问题的解决方案。

若要从远程服务器获取最新代码并将其推送到本地,请执行 git拉 git推 直接执行强制推送到远程服务器。 Git push—force

如果第一条行不通,那就使用第二条。

使用下面的命令获取所有与push相关的选项:

git push --help