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

当我使用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初始化后在本地提交一些东西。然后我使用——set-upstream推到远程。

其他回答

我不确定这是否适用,但对我来说,修复是在git初始化后在本地提交一些东西。然后我使用——set-upstream推到远程。

我的答案不是针对这个特定的问题,但可能会帮助那些有同样错误的人。 如果你在做加法。在一个空目录上提交和推,你可能会得到同样的错误。在构建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

你需要给点力

用力推就行。

就我而言,我错过了修改。我只需要运行git commit -amend,然后push。它解决了这个问题。它可能会帮助以前提交过代码的人。

在推送之前未提交初始更改也会导致问题。