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

当我使用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存储库之后,在本地目录中运行这些代码。关键在于,您需要添加/创建一个文件,并在将存储库推送到远程存储库之前提交此更改。

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

其他回答

对我来说,我忘记在点击推送之前添加和提交。

So:

git add --all
git commit -m "First commit."

然后按一下,就可以了:)

推送步骤:

git init
git add README.md      -------- or --------   git add .
git commit -m "first commit"
git remote add origin 'http github link'
git push -u origin main       ------ or -------    git push -f origin master

如果分支在main上,则:

git push -u origin main

对于主人:

git push -f origin master

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

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

尝试创建一个文件:

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

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

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

转到添加 。

Git commit -m "your msg"