我使用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

我做错了什么?


当前回答

try

   git pull --rebase

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

其他回答

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

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

git pull origin master

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

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

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

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

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”是远程服务器上调用分支的名称。它可能在本地有相同的名字,但不一定是。

看: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/

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

2) git拉