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

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

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


当前回答

在Azure DevOps中使用Git存储库时,问题在于分支策略要求所有对分支的更改必须通过pull request (PR)进行。尝试直接将更改推到分支生成错误“failed to push some refs to…”

我创建了一个公关部门,毫无问题地进行推广。

其他回答

我在GitHub帮助(处理非快进错误)中找到了这个问题的解决方案:

你可以通过获取并合并在远程分支上所做的更改和你在本地所做的更改来修复这个问题: $ git获取原点 获取在线存储库的更新 $ git合并起源分支 #将在线更新与本地工作合并 或者,你可以简单地使用git pull一次执行这两个命令: $ git拉起源分支 #获取在线更新,并将其与您的本地工作合并

如果您创建了一个空的repo并且忘记使用,也会得到这个错误

git init

在你第一次提交之前。

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

git checkout -b <nameOfNewBranch>

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

git push -u origin main出错?试试这个解决方案。它将100%工作。

Git push origin master,改为Git push origin main

如何更换Main?

git分支-M main

如果你使用git-with-ssh,它不起作用的一个原因是它可能指向错误的ssh-private-key文件或correct-file-wrong-private-key文件。如果我没记错的话,我最近在添加ssh-private-key时遇到了一些困难。所以我清空了那些妓女特工

ssh-add -D

然后一切都正常了!