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

当我使用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命令,

git push origin master –f
git push origin master --force

其他回答

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

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

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

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

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

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

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

一切都很顺利。

重命名分支,然后推送,例如:

git branch -m new-name
git push -u new-name

这对我很管用。

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

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