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

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

我的工作目录和远程存储库看起来像什么:


当前回答

Use:

git push origin {your_local_branch}:{your_remote_branch}

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

其他回答

当远程服务器有一些额外的提交时,这个问题就会出现在你的工作目录中。下面是修复此问题的解决方案。

若要从远程服务器获取最新代码并将其推送到本地,请执行 git拉 git推 直接执行强制推送到远程服务器。 Git push—force

如果第一条行不通,那就使用第二条。

使用下面的命令获取所有与push相关的选项:

git push --help

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

 rm -rf .git
 git init
 git add .
 git commit -m"first message"
 git remote add origin "LINK"
 git push -u 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 push——set-upstream origin feature /my-feature

我的分支名称缺少a in特性。我把它更正为:

Git push——set-upstream origin feature/my-feature

一切都很顺利。

通过遵循文档,你只需要把它拉到你的Github项目中。

git init -b main

git add . && git commit -m "Commit Here"

git remote add origin  <REMOTE_URL>

git remote -v

git pull origin main

git push origin main

以下是我处理这类问题的一些解决方案:

fatal:无法访问<REMOTE_URL>:请求的URL返回错误:400

git remote set-url origin <REMOTE_URL>

致命的:拒绝合并不相关的历史

git pull origin main --allow-unrelated-histories