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

当我使用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

其他回答

Use:

git push origin {your_local_branch}:{your_remote_branch}

如果本地分支和远程分支共享相同的名称,则可以省略本地分支名称。只需使用git push {your_remote_branch}。否则它会抛出这个错误。

git init Git远程添加origin https://gitlab.com/crew-chief-systems/bot Git remote -v(用于检查当前存储库) 添加所有文件 git commit -m '添加我的项目' Git pull -rebase origin master Git push origin master

对于Sourcetree用户

首先进行初始提交,或者确保没有任何未提交的更改。然后在Sourcetree的一侧有一个“REMOTES”。右键单击它,然后单击“推到原点”。好了。

在使用该命令时,我也遇到过这个问题。

Git push -u origin main

所以我使用npm cache clean——force清除了npm的所有缓存,并尝试再次push。这对我来说很有效。

Use

git push -f origin master

这个是写。