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

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

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


当前回答

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

git init

在你第一次提交之前。

其他回答

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

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

Git push -u origin main

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

我按照下面的步骤,它对我很有效。

 rm -rf .git
 git init
 git add .
 git commit -m"first message"
 git remote add origin "LINK"
 git push -u origin master

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

> 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 push——set-upstream origin feature /my-feature

我的分支名称缺少a in特性。我把它更正为:

Git push——set-upstream origin feature/my-feature

一切都很顺利。