问题描述
我在本地git仓库中设置了两个遥控器.一个是我正在贡献的开源项目的仓库,另一个是我对该仓库的分支.
I have two remotes set up in my local git repo. One is the repo of an open-source project I'm contributing to, and the other is my fork of that repo.
似乎我只能检出从 origin
遥控器上拉下来的东西.我从远程获取分支的常规方法包括
It seems that I'm only able to check out stuff that I pull down from the origin
remote. My normal method of grabbing a branch from a remote consists of
$ git fetch <remote> <branch>
$ git checkout <branch>
但这在我当前的情况下似乎不起作用.
But this doesn't seem to work in my current situation.
$ git fetch my-remote my-branch
remote: Counting objects: 2297, done.
remote: Compressing objects: 100% (1951/1951), done.
remote: Total 2297 (delta 1044), reused 0 (delta 0), pack-reused 50
Receiving objects: 100% (2297/2297), 2.10 MiB | 1.59 MiB/s, done.
Resolving deltas: 100% (1045/1045), done.
From https://github.com/me/my-repo
* branch my-branch -> FETCH_HEAD
* [new branch] my-branch -> origin/my-branch
$ git checkout my-branch
error: pathspec 'my-branch' did not match any file(s) known to git.
此外,当我执行 git branch
时,该分支不会出现.
Furthermore, the branch does not appear when I do git branch
.
这是怎么回事?
推荐答案
只有一个遥控器(我们称其为 origin
),然后键入
When you have only a single remote (let's call it origin
) then when you type
git checkout foo
当 foo
不存在但 origin/foo
确实存在时,git的行为就像您键入以下
when foo
doesn't exist but origin/foo
does exist git will behave as though you typed the following
git checkout -b foo origin/foo
如果您有多个遥控器,并且 foo
在本地不存在,但是存在于2个或更多的遥控器中,那么此行为将被抑制.
If you have multiple remotes, and foo
does not exist locally but exists in 2 or more remotes then this behavior is suppressed.
您将需要显式创建foo并指示git您要跟踪的远程/分支.
You will need to explicitly create foo and instruct git what remote/branch you want it to track.
git checkout -b foo< remote>/foo
这篇关于无法使用多个遥控器进行结帐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!