[英]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 pull
或git 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/main
和git 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/main
和git 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:
他们之中有一些是:
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.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.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.