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

当我使用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推 直接执行强制推送到远程服务器。 Git push—force

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

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

git push --help

其他回答

由于最近的“在GitHub中用main替换master”操作,如果你执行git show-ref,你可能会注意到有一个refs/heads/main。因此,下面的命令可能会从

git push heroku master

to

Git push Heroku Main

这样你的问题就解决了。

你的宣传和你的故事有关吗。如果是,检查jira的工作流程状况。 管理员可以根据某些工作流程配置为只允许推送。

通过遵循文档,你只需要把它拉到你的Github项目中。

git init -b main

git add . && git commit -m "Commit Here"

git remote add origin  <REMOTE_URL>

git remote -v

git pull origin main

git push origin main

以下是我处理这类问题的一些解决方案:

fatal:无法访问<REMOTE_URL>:请求的URL返回错误:400

git remote set-url origin <REMOTE_URL>

致命的:拒绝合并不相关的历史

git pull origin main --allow-unrelated-histories

(注意:从2020年10月开始,任何新的存储库都是用默认分支main创建的,而不是master。您可以将现有存储库默认分支从master重命名为main。 2014年剩下的答案已经更新为“main”)

(以下假设github.com本身没有崩溃,eri0o在评论中指出:查看www.githubstatus.com确认)

如果GitHub回购看到了新的提交,当你在本地工作时,我建议使用:

git pull --rebase
git push

完整的语法是:

git pull --rebase origin main
git push origin main

Git 2.6+(2015年9月),在完成(一次)之后

git config --global pull.rebase true
git config --global rebase.autoStash true

简单地拉一下就够了。 (注:与Git 2.27 Q2 2020,合并。Autostash也可用于你的常规拉,没有调整)

这样,你会在最新更新的origin/main(或origin/yourBranch: git pull origin yourBranch)上重放(——rebase部分)你的本地提交。

在第6章用rebase of the Git Pocket Book中可以看到一个更完整的例子。

我建议:

# add and commit first
#
git push -u origin main

# Or git 2.37 Q2 2022+
git config --global push.autoSetupRemote true
git push

这将在本地主分支和它的上游分支之间建立跟踪关系。 在此之后,任何对该分支的未来推送都可以使用简单的:

git push

同样,使用Git 2.37+和它的全局选项推送。autoSetupRemote,一个简单的git推送即使是第一个也会做同样的事情(即:在你的本地主分支和它的上游分支origin/main之间建立跟踪关系)。

参见“为什么我需要显式地推一个新分支?”。


因为OP已经在origin/main上重置并重做了它的提交:

git reset --mixed origin/main
git add .
git commit -m "This is a new commit for what I originally planned to be amended"
git push origin main

没必要拉,换底价。

注意:git reset——mixed origin/main也可以写成git reset origin/main,因为——mixed选项是使用git reset时的默认选项。

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