[英]Git push error "tip of your current branch is behind its remote counterpart"
I don't know why I can't push a modified file to the forked github repository.我不知道为什么我不能将修改后的文件推送到分叉的 github 存储库。
$ git checkout -b br_mahmood
Switched to a new branch 'br_mahmood'
$ git status
On branch br_mahmood
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: util/job_launching/stats/example_stats.yml
no changes added to commit (use "git add" and/or "git commit -a")
$ git add util/job_launching/stats/example_stats.yml
$ git commit -S -m "Fixing something"
You need a passphrase to unlock the secret key for
user: "mahmood <EMAIL>"
4096-bit RSA key, ID 162AF377, created 2020-09-17
[br_mahmood 0115ea6] Fixing regex for L2_BW
1 file changed, 1 insertion(+), 1 deletion(-)
$ git push -u origin br_mahmood
To https://github.com/MY_NAME/REPO
! [rejected] br_mahmood -> br_mahmood (non-fast-forward)
error: failed to push some refs to 'https://github.com/MY_NAME/REPO'
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.
By running git push
I even entered username and password.通过运行
git push
我什至输入了用户名和密码。 However, I don't know why it raises that error.但是,我不知道为什么会引发该错误。
From the error log, we can see that the remote repository already has a branch named br_mahmood
.从错误日志中,我们可以看到远程仓库已经有一个名为
br_mahmood
的分支。 It's not safe to create the local br_mahmood
from the head at that time by git checkout -b br_mahmood
.当时通过
git checkout -b br_mahmood
从头部创建本地br_mahmood
是git checkout -b br_mahmood
。 If that head belongs to another branch which diverges from the remote br_mahmood
, the local br_mahmood
is not mapping correctly.如果该头属于与远程
br_mahmood
另一个分支,则本地br_mahmood
未正确映射。 A better practice is to create br_mahmood
from the updated origin/br_mahmood
:更好的做法是创建
br_mahmood
从更新origin/br_mahmood
:
git fetch origin br_mahmood
git checkout -b br_mahmood origin/br_mahmood
The commands could still raise an error if some config values are not set properly.如果某些配置值设置不正确,这些命令仍可能引发错误。 To avoid that error:
为避免该错误:
git fetch origin br_mahmood
git checkout -b br_mahmood FETCH_HEAD
To solve the error in the log, we could use git pull origin br_mahmood
or git pull -r origin br_mahmood
before a next push.为了解决日志中的错误,我们可以在下次推送之前使用
git pull origin br_mahmood
或git pull -r origin br_mahmood
。 But, if you created the local br_mahmood
from a wrong commit at the beginning, doing so could mingle two branches which should not be.但是,如果您在
br_mahmood
从错误的提交中创建了本地br_mahmood
,那么这样做可能会混合两个不应该存在的分支。
To fix the error in your case, a safe solution is:要修复您的情况下的错误,一个安全的解决方案是:
# reset the local "br_mahmood" to the head of the remote "br_mahmood"
git fetch origin br_mahmood
git reset FETCH_HEAD --hard
# apply the commit "0115ea6" onto to the updated "br_mahmood"
git cherry-pick 0115ea6
# update "br_mahmood" to avoid the "non-fast-forward" push error,
# in case the remote "br_mahmood" has been updated by others
git pull origin -r br_mahmood
# push again
git push origin -u br_mahmood
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.