简体   繁体   English

GitHub更新被拒绝,因为当前分支的提示位于其远程对应的后面

[英]GitHub updates were rejected because the tip of current branch is behind its remote counterpart

I suppose I get the basics of GitHub - I understand initializing a repository on my local machine, committing, pushing, pulling, cloning, etc. But when it comes to branches and such, I am completely lost. 我想我掌握了GitHub的基础知识-我了解在本地计算机上初始化存储库,提交,推送,拉取,克隆等。但是当涉及到分支等时,我完全迷失了。

Right now I'm trying to push my most recent version of a project, and I can't. 现在,我正在尝试推送项目的最新版本,但我不能。 The following things are true: 以下内容是正确的:

  1. the repository on the website is mine and I am the only collaborator on this project; 网站上的存储库属于我,我是该项目的唯一合作者;

  2. this site is my portfolio. 这个网站是我的投资组合。 I've only ever created the master branch, but there is a "developing" branch that I did not create, but I assume that is default when you create a portfolio on GitHub Pages. 我只创建了master分支,但是没有创建一个“开发中”分支,但是我认为在GitHub Pages上创建投资组合时,这是默认的。

  3. I've pushed to this project several times before, and it is always a problem. 我之前曾多次推动该项目,但这始终是一个问题。

As I said, I'm trying to push my most recent version. 正如我所说,我正在尝试推送最新版本。 Here is what happens: 这是发生了什么:

I check the branch that I'm in, and it says I'm in "master". 我检查了我所在的分支,它说我在“主”中。 I add, commit, and try to push through my terminal. 我添加,提交并尝试通过我的终端。 It asks me for my username and password, I put them in, and it returns: 它要求我输入用户名和密码,然后将它们输入,然后返回:

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/...(my portfolio      address)...io.git'
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.

So then I tried to pull, and received this: 因此,我尝试拉动,并收到以下消息:

There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

   git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

  git branch --set-upstream-to=origin/<branch> master

I don't understand this. 我不明白 What exactly does it mean to be behind a branch? 在分支机构后面究竟意味着什么? I thought I understood that but clearly I don't. 我以为我明白,但显然我不明白。 And even if I got it, how can my own branch be behind itself? 即使我明白了,我自己的分支机构又该如何落后呢? I've never pushed to any other branch! 我从未去过其他任何分支!

Based on the comments, it sounds like you have made a mess here that you will have to clean up one way or another. 根据评论,听起来您在这里一团糟,您将不得不采用一种或另一种方式进行清理。 However, the immediate solution to the immediate problem: 但是,立即解决问题的方法是:

 There is no tracking information for the current branch. 

is the one Git is telling you to do: 是Git告诉您要做的事情:

 git branch --set-upstream-to=origin/<branch> master 

In particular, you obviously want origin/master set as the upstream for master : 特别是,你显然希望origin/master设定为上游的master

git branch --set-upstream-to=origin/master master

Now all three commands— git pull , 1 git merge , and git rebase —will know that you want to keep your master in sync with your Git's memory of some other Git's master . 现在,这三个命令( git pull1 git mergegit rebase将知道您想使您的master与其他Git master Git内存保持同步。

Your Git, at certain points (when you tell it to), connects to origin , finds out what they have in their master, brings over anything required, and sets your origin/master to remember this. 你的Git,在某些点(当你告诉它),连接到origin ,发现他们有什么自己的主人,拥有超过需要的东西,并设置您的 origin/master记住这一点。 The main point of contact is you running git fetch or git fetch origin (if you leave out the origin , Git figures out which remote you mean to use, or guesses origin if all else fails). 联系的主要点是您运行git fetchgit fetch origin (如果不考虑origin ,Git会指出您打算使用哪个远程,或者如果所有其他方法都失败,则猜测origin )。

Once you have the updated memory, you can compare what you have (your master ) to what your Git remembers that they have (your origin/master ). 一旦拥有了更新的内存,就可以将自己拥有的(您的master )与Git记住它们拥有的(您的origin/master )进行比较。 If it's time to do so, you can git merge or git rebase your master, to merge or rebase using (your memory of) theirs. 如果需要这样做,则可以对主数据库进行git mergegit rebase ,以使用其记忆(对您的记忆)进行合并或对基础。

You may get merge conflicts! 您可能会遇到合并冲突! These are normal: they just mean that you changed something in some file, and they (whoever they are) changed something in the same file, and both of you touched the same lines of that file, but you and they did different things to the lines. 这是正常现象:它们只是意味着更改了某个文件中的某些内容,而他们 (无论它们是什么)更改了同一文件中的某些内容,而你们两个都触摸了该文件的同一 ,但是您和他们对文件所做的不同线。 Git doesn't know whether you're smarter than they are, or they are smarter than you are, or what. Git不知道您是否比他们聪明,或者他们比您聪明,或者什么。 It just puts both changes into your file and makes you clean up the mess. 它只是将两个更改都放入您的文件中,并使您清理混乱。 You must now edit the conflicting file(s), put the right lines into them, and save them back to the work-tree; 现在,您必须编辑有冲突的文件,将正确的行放入其中,然后将其保存回工作树中。 then git add and git commit the final results of all the merging. 然后git addgit commit所有合并的最终结果。

(If you use git rebase instead of git merge , you will still get merge conflicts, but once you have resolved them and git add -ed the files, you should run git rebase --continue instead of git commit . See many other SO questions and answers on merge and rebase.) (如果您使用git rebase而不是git merge ,则仍然会发生合并冲突,但是一旦解决了它们并git add -ed文件,则应该运行git rebase --continue而不是git commit 。请参阅其他许多问题以及合并和变基的答案。)


I recommend avoiding git pull because it does too much: it first runs git fetch for you, then runs git merge for you. 我建议避免使用git pull因为它做的太多:它首先为您运行git fetch ,然后为您运行git merge (Or it runs git rebase for you instead of git merge , if you tell it so.) Now, it's true that after git fetch , you very often want to run one of these other two commands ... but you don't necessarily want to run it right away . (或者,如果您这样说的话,它会为您运行git rebase而不是git merge 。)现在,的确是,在git fetch ,您经常想运行另外两个命令之一……但是您不一定要运行它的时候了 And, you have two commands to try: how do you know which one you want? 并且,您有两个命令可以尝试:您如何知道想要哪个? And if things go wrong—which they do—how do you know which command's help to look for? 而且,如果出现错误(它们会做什么),您如何知道要寻找哪个命令的帮助? If you run the merge or rebase yourself, you have the answers to all of these. 如果您自己运行合并或重新设置基准,那么您将获得所有这些的答案。 This is why I say: forget about git pull , just stick with git fetch and whichever other second command you prefer. 这就是为什么我说:忘记git pull ,只坚持git fetch和您喜欢的其他第二个命令。

暂无
暂无

声明:本站的技术帖子网页,遵循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 如何修复Git中的问题:“更新被拒绝,因为推送的分支提示位于其远程对应的后面” - How to fix issue in Git: “Updates were rejected because a pushed branch tip is behind its remote counterpart” 推送到 github 时出错 - 更新被拒绝,因为推送的分支提示在其远程后面 - Getting an error pushing to github - Updates were rejected because a pushed branch tip is behind its remote git 推送 - 更新被拒绝,因为当前分支的尖端落后于远程对应 - git push - updates rejected because tip of current branch behind remote counterpart 更新被拒绝,因为您当前分支的提示落后 - 但为什么? - Updates were rejected because the tip of your current branch is behind - but why? 更新被拒绝,因为您当前分支的尖端在后面...不正确 - Updates were rejected, because the tip of your current branch is behind… Not true Github 错误“更新被拒绝,因为您当前分支的提示落后” - Github error "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?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM