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

当我使用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存储库之前提交您的更改。这可能会解决你的问题。

其他回答

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

ssh-add -D

然后一切都正常了!

记得在推送到GitHub存储库之前提交您的更改。这可能会解决你的问题。

在我的案例中,Git预推钩子有一个问题。

运行git push——verbose查看是否有任何错误。

在. Git /hooks目录下仔细检查你的Git钩子,或者将它们临时移动到另一个地方,看看之后是否一切正常。

你需要给点力

用力推就行。

我的答案不是针对这个特定的问题,但可能会帮助那些有同样错误的人。 如果你在做加法。在一个空目录上提交和推,你可能会得到同样的错误。在构建Github存储库之后,在本地目录中运行这些代码。关键在于,您需要添加/创建一个文件,并在将存储库推送到远程存储库之前提交此更改。

echo "# something" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/[address of your repository].git
git push -u origin main