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

当我使用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预推钩子有一个问题。

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

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

其他回答

在push之前,你必须添加并提交更改,或者执行git push -f 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 commit -amend,然后push。它解决了这个问题。它可能会帮助以前提交过代码的人。

我按照下面的步骤,它对我很有效。

 rm -rf .git
 git init
 git add .
 git commit -m"first message"
 git remote add origin "LINK"
 git push -u origin master

我在GitHub中创建了一个空的存储库,并在本地有我的代码。我现在面临着同样的问题,我按照下面的顺序,

git init
git commit -m 'Initial Commit'
git remote add origin https://github.com/kavinraju/Repo-Name.git
git add .
git push -u origin master

问题是:我试图在暂存我拥有的文件之前提交。

所以我们需要暂存文件,然后提交。

这是正确的顺序。

git init
git add .
git commit -m 'Initial Commit'
git remote add origin https://github.com/kavinraju/Repo-Name.git
git push -u origin master

因为我首先执行了错误的序列,所以我只执行了下面的命令:

git add .
git commit -m 'Initial Commit'
git push -u origin master