简体   繁体   English

Git 推送错误“您当前分支的提示落后于其远程对应分支”

[英]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_mahmoodgit 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_mahmoodgit 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.

相关问题 git push错误:当前分支位于其远程对应对象的后面 - git push error: current branch is behind its remote counterpart 推送到远程失败,因为“当前分支的尖端位于其远程对应部分之后” - Pushing to remote fails because “tip of your current branch is behind its remote counterpart” GitLab 更新被拒绝,因为您当前分支的尖端落后于其远程对应分支 - GitLab Updates were rejected because the tip of your current branch is behind its remote counterpart 更新被拒绝,因为你当前分支的尖端落后于它的远程分支 - Updates were rejected because the tip of your current branch is behind its remote counterpart Git分支提示位于其远程对应项的后面,并防止“推送” - Git branch tip is behind it's remote counterpart and is preventing a 'push' git 推送 - 更新被拒绝,因为当前分支的尖端落后于远程对应 - git push - updates rejected because tip of current branch behind remote counterpart 当我运行“git push”时,我得到“您当前分支的提示在其远程后面”但当前分支没有上游跟踪分支 - When I run "git push" I get "tip of your current branch is behind its remote" but the current branche has no upstream tracking branch git-我需要推送我的最新更改,并得到我的分支提示落后于远程对等方的错误 - git - I need to push my latest changes and get error that my branch tip is behind remote counterpart 当前分支落后于其远程分支 - Current branch is behind its remote counterpart GitHub更新被拒绝,因为当前分支的提示位于其远程对应的后面 - GitHub updates were rejected because the tip of current branch is behind its remote counterpart
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM