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

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

其他回答

在Azure DevOps中使用Git存储库时,问题在于分支策略要求所有对分支的更改必须通过pull request (PR)进行。尝试直接将更改推到分支生成错误“failed to push some refs to…”

我创建了一个公关部门,毫无问题地进行推广。

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

Git push -u origin main

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

在我的例子中,分支名称前缀已经存在于远程,所以基本上,如果你有一个分支名称“fix”,你不能推送另一个名称为“fix/new_branch_name”的分支。

重命名分支解决了我的问题。

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

转到添加 。

Git commit -m "your msg"

如果您创建了一个空的repo并且忘记使用,也会得到这个错误

git init

在你第一次提交之前。