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

当我使用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 add .
git commit -m "first commit"
git push --set-upstream origin master

其他回答

因为也许它没有什么可推的(真的,没有什么可推的)。这样做:

git remote add origin https://github.com/donhuvy/accounting133.git
git remote -v
git add .
git commit -m"upload"
git push --set-upstream origin master

在您的情况下更改远程存储库的URL。你可以跳过命令git remote -v,只是为了检查。

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

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"

我尝试了'git push origin main',然后收到了消息。然后我尝试单独使用“git push”,但它不起作用。

我检查了一下我是否承诺了(是的)。我试着“拉”,然后“推”,但没有。

在开始一些特技之前,我只是关闭并打开一个新的终端,然后再次“推”,它工作了:p

由于最近的“在GitHub中用main替换master”操作,如果你执行git show-ref,你可能会注意到有一个refs/heads/main。因此,下面的命令可能会从

git push heroku master

to

Git push Heroku Main

这样你的问题就解决了。

你需要给点力

用力推就行。