有人能进一步解释一下用git签出远程分支吗?



我已经看了这里的几个问题,特别是这个问题,但我仍然很困惑。

我有一个服务器设置了一个缓慢的上行链路,我通过SSH隧道访问。在它上面,我克隆了一个Linux内核的裸存储库(来源指向kernel.org)。然后我在我的机器上克隆了裸仓库,签出标签,创建了一个分支(比如"test"),在该分支上做了更改,最后将更改推送到我的服务器上的裸仓库。

现在我在一个客户端站点,想要签出分支。为了避免我在客户端站点上的缓慢上行,我从kernel.org上克隆了linux repo,并将"origin"更改为通过SSH隧道指向我的服务器。我可以看到分支,但是不能检查它:

~/linux-3.0.y$ git version
git version 1.7.0.4
~/linux-3.0.y$ 
~/linux-3.0.y$ git status
# On branch master 
nothing to commit (working directory clean)
~/linux-3.0.y$ 
~/linux-3-0.y$ git remote show origin
git-user@localhost's password:
* remote origin
  Fetch URL: git+ssh://git-user@localhost:48884/home/git-user/linux-3.0.y
  Push  URL: git+ssh://git-user@localhost:48884/home/git-user/linux-3.0.y
  HEAD branch: master
  Remote branches:
    test    new (next fetch will store in remotes/origin)
    master  new (next fetch will store in remotes/origin)
  Local ref configured for 'git push':
    master pushes to master (up to date)
~/linux-3.0.y$ 
~/linux-3.0.y$ git checkout -b test origin/test
fatal: git checkout: updating paths is incompatible with switching branches.
Did you intend to checkout 'origin/test' which can not be resolved as commit?

我实际上想要的是能够在我客户的网站上创建的分支上工作。我应该做什么(已经做了)签出这个分支?

首先,你似乎没有获取分支。

git branch -a代替git remote show origin

如果测试分支缺失,则执行git fetch --all

现在,如果您想将远程分支签出为具有相同名称的本地分支,只需执行git checkout BRANCH_NAME,它将自动设置为跟踪源。