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

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

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


当前回答

如果你试图用一个现有的GitHub存储库初始化一个目录,你应该确保你正在提交更改。

尝试创建一个文件:

touch initial
git add initial
git commit -m "initial commit"
git push -u origin master

这将放置一个名为initial的文件,您可以稍后删除该文件。

其他回答

对我来说,问题是我没有在提交之前添加文件。

转到添加 。

Git commit -m "your msg"

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

> 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 init并添加了git add文件。或者类似的东西,并且添加了远程分支,它可能是你还没有在本地提交(git commit -m 'commit message')任何东西来推送到远程…我只是有这个错误,这是我的问题。

试着用

git status

你的分支是基于“origin/main”的,但是上游已经没有了。

然后执行以下步骤

git branch --unset-upstream
git push --set-upstream origin main

我也遇到过同样的问题,并通过以下步骤解决了它。

git init Git添加。 git commit -m '添加提交信息' git远程添加origin https://User_name@bitbucket.org/User_name/sample.git (上面的URL, https://User_name@bitbucket.org/User_name/sample.git,指的是你的Bitbucket项目的URL) Git push -u origin master

Hint

检查你的GitHub账户是否连接到你的本地Git存储库:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"