我使用github的时间相对较短,我总是使用客户端来执行提交和拉取。昨天我决定从git bash中尝试一下,我成功地创建了一个新的repo和提交文件。

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

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>

这个回购的唯一贡献者是我,没有分支(只有一个主)。我在窗口上,我已经执行了从git bash的拉:

git 状态:

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

git 分支:

$ git branch
* master

我做错了什么?


你可以指定你想要拉哪个分支:

git pull origin master

或者你可以设置它,让你的本地主分支跟踪github主分支作为上游:

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

当您克隆存储库(仅针对默认分支)时,该分支跟踪将自动为您设置,但如果您将远程添加到现有存储库,则必须自己设置跟踪。值得庆幸的是,git给出的建议让你很容易记住该怎么做。


看:git签出标签,git拉失败在分支

如果你像我一样需要一直这样做,你可以通过在你的.gitconfig文件中添加以下内容来设置一个别名来自动完成:

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

当你看到这个消息没有跟踪信息…运行:

 git set-upstream
 git push

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


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

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


1) git branch——set-upstream-to=origin/<master_branch> feature/<your_current_branch>

2) git拉


我尝试了上面的例子,但无法让它们与我在另一台计算机上创建的(非主)分支同步。对于后台,我在计算机A (git v 1.8)上创建了这个存储库,然后将该存储库克隆到计算机B (git 2.14)上。我在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

try

   git pull --rebase

希望这个答案对你有帮助,原来的答案在这里https://stackoverflow.com/a/55015370/8253662


有了Git 2.24(2019年Q4),你就不必这么做了

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

你将能够做到:

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

参见“默认远程和分支使用-u选项-适用于推而不是拉”。


注意,在Git 2.37 (Q3 2022)中,你有一个新的选项push.autoSetupRemote

git config --global push.autoSetupRemote true

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


$ git分支——set-upstream-to=heroku/master master 而且

$ git pull

为我工作!


同样的事情也发生在我之前,当我创建了一个新的git分支,而没有把它推到原点。

试着先执行这两行:

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

然后:

git pull origin name_of_new_branch

现在应该没事了!


发生这种情况是因为当前分支没有跟踪远程上的分支。有两种方法。

使用特定的分支名称进行拉取 Git拉源主 或者可以将特定的分支跟踪到本地分支。 git分支——set-upstream-to=origin/<branchName>


Git分支——set-upstream-to=origin/main


试着用

git push --set-upstream origin <branch_name>

否则

use

git push -u 

会告诉你该怎么做。


对于任何想要了解为什么会发生这种情况的人来说,有几个相关的概念:

A git repository can have zero or more "remotes", which are named links to other repositories, usually on some central server somewhere. You can list them with "git remote -v" If you clone a repository from another server, a default remote called "origin" will be set up for you. The full syntax for both git push and git pull is to specify a remote name and a branch on that remote. A local branch can be associated with a branch on a remote, so that you don't have to type it each time you pull or push. If you check out a branch from a remote repository using "git switch branchname" or "git switch -u origin/branchname", the association will be set for you. ("git switch" is the same in this case as "git checkout") If you create a branch locally and then push it with "git push -u origin", it will set the association. But if you don't include the "-u" in the initial pull or push, the association won't be stored, so you have to be specific every time.

正如其他答案指出的那样,解决方案是使用“git branch——set-upstream-to=origin/branchname”来设置关联,其中“origin”是远程服务器的名称,而“branchname”是远程服务器上调用分支的名称。它可能在本地有相同的名字,但不一定是。


步骤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添加。Git提交。 然后我执行下面的步骤,我的推动是成功的

推动变革

执行

git push -f origin master