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

当我使用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 rm --cached *
git add .
git commit -m"upload"
git push --set-upstream origin master

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

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

这些步骤对我很有效:

切换到当前分支和拉最新的代码 重命名本地分支 Git分支-m [new-name] 将本地分支推到服务器 Git push origin [new-name] 从服务器中删除分支 Git push origin——delete [old-name]

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

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

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

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