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

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

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


当前回答

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

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

其他回答

Git错误:当本地存储库名称与相应的远程存储库名称匹配时,也会出现未能推一些引用。在将更改拉入远程存储库之前,请确保您正在使用正确的存储库对。

如果拼写错误,并且希望删除本地存储库,请执行以下步骤。

删除Windows上的本地存储库:

del /F /S /Q /A .git 删除目录. 更正本地文件夹名称(XXXX02->XXXX20),或者如果是新创建的repo,则删除它并重新创建repo (XXXX02 repo名称更改为XXXX20)。 git init 如果没有映射,则使用远程repo重新映射。 git remote add origin https://github.com/<username>/XXXX20.git . zip Git push -u origin master

不幸的是,我无法用其他解决方案解决这个问题,但我的问题是我想要推送的分支名称不被远程接受。我把它改成了正确的格式,它被接受了。

它是test/testing_routes,我需要将其更改为testing_route,其中正斜杠(/)是远程不允许的。

您应该确保分支名称格式正确。

事实上,GitHub将master改为main让我遇到了这个问题。所以从现在开始,推到原点的解决方案是:

git push -u origin main

对我来说,问题是我没有在提交之前添加文件。

转到添加 。

Git commit -m "your msg"

我也遇到过同样的问题,并通过以下步骤解决了它。

git init Git添加。 git commit -m '添加提交信息' git远程添加origin https://User_name@bitbucket.org/User_name/sample.git (上面的URL, https://User_name@bitbucket.org/User_name/sample.git,指的是你的Bitbucket项目的URL) Git push -u origin master

Hint

检查你的GitHub账户是否连接到你的本地Git存储库:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"