简体   繁体   English

git 推送 - 更新被拒绝,因为当前分支的尖端落后于远程对应

[英]git push - updates rejected because tip of current branch behind remote counterpart

I created a new branch and made changes to the code and attempted to push我创建了一个新分支并对代码进行了更改并尝试推送

git add .
git checkout -b newbranch
git commit -m "commit"
git push origin newbranch

I get error: failed to push some refs.. updates were rejected because the tip of your current branch is behind its remote counterpart..我收到error: failed to push some refs.. updates were rejected because the tip of your current branch is behind its remote counterpart..

if I do git pull or git pull --rebase , I get如果我做git pullgit pull --rebase ,我得到

there is no tracking information for the current branch. Please specify which branch you want to merge with

if I try git rebase origin/main and git pull origin main --rebase , it says如果我尝试git rebase origin/maingit pull origin main --rebase ,它会说

current branch newbranch is up to date

if I try git pull origin/main and git pull main , it says如果我尝试git pull origin/maingit pull main ,它会说

fatal: origin/main does not appear to be a git repository

if I try git pull origin main , it says如果我尝试git pull origin main ,它会说

fatal: not possible to fast-forward, aborting

can anyone help?谁能帮忙?

The title error message is likely because you created a branch with the same name as one that already exists on the remote.标题错误消息可能是因为您创建了一个与远程已经存在的分支同名的分支。 So when you attempt to push it Git is informing you that there are commits on the remote tracking branch with that name that you do not have yet.因此,当您尝试推送它时,Git 会通知您远程跟踪分支上存在您尚未使用的名称的提交。

You can confirm by listing all the remote branches with git branch -r .您可以通过使用git branch -r列出所有远程分支来确认。

If that's the problem there are lots of things you can do to solve this.如果这是问题所在,您可以采取很多措施来解决这个问题。 Some of them are:他们之中有一些是:

  1. Rename your branch to something else.将您的分支重命名为其他名称。 Then when you push it you won't conflict with an already existing branch.然后当你推送它时,你不会与已经存在的分支冲突。
  2. If you feel your branch should get the new commits from the remote branch, then perform git pull origin newbranch to merge them in (or use git pull --rebase origin newbranch if you don't want to create a merge commit for this).如果您认为您的分支应该从远程分支获取新提交,则执行git pull origin newbranch以将它们合并(或使用git pull --rebase origin newbranch如果您不想为此创建合并提交)。 After that you'll be able to cleanly push.之后,您将能够干净利落地推动。
  3. If your intent was to blow those commits away on the remote branch, then you could do a force push, with git push --force-with-lease .如果您的意图是在远程分支上删除这些提交,那么您可以使用git push --force-with-lease进行强制推送。 If that still failed then it means there are commits on the remote repo that you haven't even fetched yet, so you would need to git fetch (and probably look at the commits to make sure you don't want them) and then perform the force push again.如果仍然失败,那么这意味着远程 repo 上存在您尚未获取的提交,因此您需要git fetch (并且可能查看提交以确保您不想要它们)然后执行力量再次推动。

I'm not sure which option is best for you, but I definitely would not do #3 unless you know for sure you don't need what's on the remote branch of the same name.我不确定哪个选项最适合您,但我绝对不会做#3,除非您确定您不需要同名远程分支上的内容。 If you aren't sure which is best I'd lean towards option #1, for now.如果您不确定哪个是最好的,我现在倾向于选项#1。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更新被拒绝,因为你当前分支的尖端落后于它的远程分支 - Updates were rejected because the 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 GitHub更新被拒绝,因为当前分支的提示位于其远程对应的后面 - GitHub updates were rejected because the tip of current branch is behind its remote counterpart 如何修复Git中的问题:“更新被拒绝,因为推送的分支提示位于其远程对应的后面” - How to fix issue in Git: “Updates were rejected because a pushed branch tip is behind its remote counterpart” 在'git filter-branch`之后无法推送到Heroku:更新被拒绝,因为当前分支的提示落后了 - Can't push to Heroku after a `git filter-branch`: Updates were rejected because the tip of your current branch is behind 如何解决git错误:重命名远程分支时“更新被拒绝,因为当前分支的提示落后” - How to resolve git error: “Updates were rejected because the tip of your current branch is behind” when renaming a remote branch Git 更新被拒绝,因为您当前分支(主)的尖端在后面但是分支是最新的? - Git Updates were rejected because the tip of your current branch (main) is behind BUT branch is up to date? Git分支提示位于其远程对应项的后面,并防止“推送” - Git branch tip is behind it's remote counterpart and is preventing a 'push' Git 推送错误“您当前分支的提示落后于其远程对应分支” - Git push error "tip of your current branch is behind its remote counterpart" 源树推送:提示:更新被拒绝,因为当前分支的尖端落后 - Source Tree Push : hint: Updates were rejected because the tip of your current branch is behind
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM