没有当前分支机构的跟踪信息

我从相对较短的时期开始使用github,并且我一直使用客户端执行提交和拉取。我昨天决定从git bash尝试它,我成功创建了一个新的存储库和提交文件。

今天我从另一台计算机对存储库进行了更改,我已经提交了更改,现在我回到家中并执行了git pull来更新我的本地版本,我得到了这个:

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 develop origin/<branch>

这个仓库的唯一贡献者是我,没有分支(只有一个主)。我在windows上,我已经执行了git bash的拉取:

在此处输入图片描述

git状态:

$ git status# On branch masternothing to commit, working directory clean

git分支:

$ git branch* master

我做错了什么?

808992 次浏览

您可以指定要拉取的分支:

git pull origin master

或者您可以设置它,以便您的本地master分支将github master分支跟踪为上游:

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

当您克隆存储库(仅适用于默认分支)时,会自动为您设置此分支跟踪,但如果您将远程添加到现有存储库,则必须自己设置跟踪。幸运的是,git提供的建议使您很容易记住如何做到这一点。

见:git检出标签,分支中git拉取失败

如果像我一样,您需要一直这样做,您可以通过将以下内容添加到.gitconfig文件中来设置别名来自动执行此操作:

[alias]set-upstream = \!git branch \--set-upstream-to=origin/`git symbolic-ref --short HEAD`

当您看到消息There is no tracking information...时,运行:

 git set-upstreamgit push

感谢https://zarino.co.uk/post/git-set-upstream/

我经常遇到这个消息,因为我通过git checkout -b <feature-branch-name>创建了一个本地分支,而没有首先创建远程分支。

在所有工作完成并在本地提交后,修复程序是git push -u,它创建了远程分支,推送了我的所有工作,然后是合并请求URL。

1)git分支--set-usver-to=起源/<master_branch>特征/<your_current_branch>

2)git拉取

我正在尝试上述示例,但无法让它们与我在另一台计算机上创建的(非主)分支同步。作为背景,我在计算机A上创建了这个存储库(git v 1.8),然后将该存储库克隆到计算机B上(git 2.14)。我在comp B上进行了所有更改,但是当我试图将更改拉到计算机A上时,我无法这样做,得到了上面相同的错误。类似于上述解决方案,我必须做:

git branch --set-upstream-to=origin/<my_branch_name>git pull

略有不同,但希望能帮助某人

ComputerDruid的答案很好,但我认为没有必要手动设置上游,除非你想。我添加这个答案是因为人们可能认为这是一个必要的步骤。

如果您指定要拉取的遥控器,此错误将消失,如下所示:

git pull origin master

请注意,origin是远程的名称,master是分支名称。


1)如何检查远程名称

git remote -v

2)如何查看存储库中可用的分支。

git branch -r

尝试

   git pull --rebase

希望这个答案有助于最初在这里回答https://stackoverflow.com/a/55015370/8253662

使用Git 2.24(2019年第四季度),您不必做

git branch --set-upstream-to=origin/main maingit pull

您将能够做到:

git pull --set-upstream-to=origin/main main

查看更多“使用#0选项的默认远程和分支-适用于#1但不适用于#2”。


请注意,在Git 2.37(2022年第三季度)中,您拥有新选项#0

git config --global push.autoSetupRemote true

然后一个简单的git push将与git push --set-upstream-to=origin/main main相同,使下一个git pull已经设置为从origin/main检索提交。

$ git branch --set-upstream-to=heroku/master master

$ git pull

为我工作!

同样的事情发生在我之前,当我创建一个新的git分支,而不是推动它的起源。

首先尝试执行这两行:

git checkout -b name_of_new_branch # create the new branchgit push origin name_of_new_branch # push the branch to github

然后:

git pull origin name_of_new_branch

现在应该没事了!

这发生由于当前分支没有跟踪分支上的远程.所以你可以做到这一点与2种方式。

  1. 使用特定的分支名称拉取

    git pull origin master

  2. 或者您可以将特定分支跟踪到本地分支。

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

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

尝试使用

git push --set-upstream origin <branch_name>

否则

使用

git push -u

他会告诉你需要做什么。

对于任何想要理解为什么发生这种情况的人来说,有一些相关的概念:

  • git存储库可以有零个或多个“远程”,它们被命名为指向其他存储库的链接,通常位于某个中央服务器上。您可以使用“git远程-v”列出它们
  • 如果您从另一台服务器克隆存储库,将为您设置一个名为“起源”的默认远程。
  • git ush和git拉取的完整语法是在该远程上指定一个远程名称和一个分支。
  • 本地分支可以与远程分支相关联,这样您就不必每次拉或推时都键入它。
  • 如果您从远程存储库中签出一个分支,使用“git Switch分支名称”或“git Switch-u起源/分支名称”,将为您设置关联。(在这种情况下,“git Switch”与“git Check out”相同)
  • 如果你在本地创建了一个分支,然后使用“git push-u的起源”推送它,它将设置关联。
  • 但是如果在初始拉取或推送中不包含“-u”,则不会存储关联,因此每次都必须具体。

正如其他答案所指出的那样,解决方案是设置与“git分支--set-usuper-to=起源/分支名称”的关联,其中“起源”是远程服务器的名称,“分支名称”是远程服务器上调用的分支。这可能与它在本地的名称相同,但不必如此。

步骤1

$ git pull
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=<remote>/<branch> master

步骤2

$ git branch -u origin/master
Branch 'master' set up to track remote branch 'master' from 'origin'.

步骤3

$ git pull
Already up to date.

这个答案最适合

谁希望将他们的存储库链接到他们的项目并提交更改

根据椰子的回答

步骤1

git pull
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=<remote>/<branch> master

步骤2

git branch -u origin/master
Branch 'master' set up to track remote branch 'master' from 'origin'.

步骤3

git pull
Already up to date.

问题

我花了几个小时提交我的更改我按照上面的步骤和git add .git commit .然后我执行了下面的步骤,我的推送成功了

推动变革

执行

git push -f origin master