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

当我使用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 add .
git commit -m "first commit"
git push --set-upstream origin master

在使用该命令时,我也遇到过这个问题。

Git push -u origin main

所以我使用npm cache clean——force清除了npm的所有缓存,并尝试再次push。这对我来说很有效。

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

Git push origin master,改为Git push origin main

如何更换Main?

git分支-M main

试试这个Git命令,

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

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