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

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

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


当前回答

在我们的例子中,重新尝试push解决了问题。可能是网络速度慢导致了这个问题。

其他回答

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

git push -u origin main

对我来说,是我的哈士奇包裹阻止了我的推进。

> husky - pre-push hook failed (add --no-verify to bypass)
> husky - to debug, use 'npm run prepush'
error: failed to push some refs to 'https://username@bitbucket.org/username/my-api.git'

要强制执行,只需运行git push origin master——no-verify

我运行npm run prepush来调试错误,这就是原因:

npm ERR! code ELOCKVERIFY
npm ERR! Errors were found in your npm-shrinkwrap.json, run  npm install  to fix them.
npm ERR!     Invalid: lock file's loopback-utils@0.8.3 does not satisfy loopback-utils@^0.9.0

运行npm install并提交,问题就解决了。

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

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

然后一切都正常了!