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

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

实际上,我忘记添加并提交我的更改,只是第一次尝试推送它。

git init
git remote add origin https://github.com/anything/repo-name.git
git add .
git commit -m "Changes"
git branch -M main
git push -u origin main

希望这能有所帮助!

其他回答

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

尝试创建一个文件:

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

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

Use

git push -f origin master

这个是写。

这些步骤对我很有效:

切换到当前分支和拉最新的代码 重命名本地分支 Git分支-m [new-name] 将本地分支推到服务器 Git push origin [new-name] 从服务器中删除分支 Git push origin——delete [old-name]

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

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

如果您正在使用Gerrit,这可能是由提交中不适当的Change-id引起的。尝试删除Change-Id,看看会发生什么。