我在更新 GitHub 上的存储库时一直遇到同样的问题,无论我在 git push 中输入什么,我都会收到错误

问题描述 投票:0回答:1

我是一名 Windows 用户,我刚刚开始使用 GitHub,并将数据添加到此 GitHub 存储库,但无法更新。我想我只是在更新时推送时出错了。我有 1 个分支,主要的。我不明白为什么问题仍然出现

C:\\Users\\PC\\Downloads\\Projelerim\\Projelerim\\myWork\>git push -u origin main

To github.com:cengizVenes/myWork.git

 ! \[rejected\]        main -\> main (non-fast-forward)

error: failed to push some refs to 'github.com:cengizVenes/myWork.git'

hint: Updates were rejected because the tip of your current branch is behind

hint: its remote counterpart. If you want to integrate the remote changes,

hint: use 'git pull' before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for details.
git github github-for-windows
1个回答
0
投票

正如您在错误中看到的那样:

hint: Updates were rejected because the tip of your current branch is behind

这意味着您当前在 github 上的分支已更改(由其他人或可能由您自己更改),现在它与您系统中当前的分支不同。

为了解决这个问题,你必须先拉再推。正如你所看到的提示:

hint: use 'git pull' before pushing again.

所以,在这种情况下我通常使用

fetch
命令而不是
pull
。(为了更好地控制代码。) 在终端上运行这些命令:

git fetch origin master:test
git rebase test
git push origin HEAD:master
git branch -D test

我希望它能得到解决。 (我知道另一种方法来解决这个问题,但我必须搜索,因为我忘记了它的一些命令。所以如果上面的命令不起作用。请告诉我。也许我会为你搜索它。)

© www.soinside.com 2019 - 2024. All rights reserved.