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

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

ssh-add -D

然后一切都正常了!

其他回答

Use

git push -f origin master

这个是写。

通过遵循文档,你只需要把它拉到你的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

我不确定这是否适用,但对我来说,修复是在git初始化后在本地提交一些东西。然后我使用——set-upstream推到远程。

这些步骤对我很有效:

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

如果您正在使用Gerrit,这可能是由提交中不适当的Change-id引起的。尝试删除Change-Id,看看会发生什么。