为什么git checkout“origin / branch-name”导致git 1.5中的“no branch”?

时间:2012-02-28 09:55:11

标签: git

这个问题似乎源于我对git 1.5缺乏经验,因为如果我尝试使用1.7的系统,这种方法就可以了。为什么我最终选择“没有分支”,更重要的是,我能做些什么来达到“interesting_branch”的HEAD?

$ git --version
git version 1.5.6.5
git clone git@git.example.com:path/to/repo
Initialized empty Git repository in some/local/path/.git
<snip>
cd path
git branch -a
* master
  origin/HEAD
  origin/develop
  origin/feature-cg-interesting_branch
$ git checkout feature-cg-interesting_branch
error: pathspec 'feature-cg-interesting_branch' did not match any file(s) known to git.
$ git checkout -- feature-cg-interesting_branch
error: pathspec 'feature-cg-interesting_branch' did not match any file(s) known to git.
$ git checkout origin/feature-cg-interesting_branch
Note: moving to "origin/feature-cg-interesting_branch" which isn't a local branch
If you want to create a new branch from this checkout, you may do so
(now or later) by using -b with the checkout command again. Example:
  git checkout -b <new_branch_name>
HEAD is now at 6534d1d... [Commit message]
$ git branch 
  * (no branch)
  master

2 个答案:

答案 0 :(得分:5)

您需要手动创建本地跟踪分支:

$ git checkout -b feature-cg-interesting_branch origin/feature-cg-interesting_branch

除了master

之外,您应该为每个remore分支执行此操作

答案 1 :(得分:1)

origin/master不是本地分支,因此它使您的存储库处于分离头状态(例如,当您通过哈希检出标记或提交时)。远程分支用于跟踪上次与远程存储库同步时每个分支的最后状态。

当您想要进一步开发该分支时,您需要创建一个本地分支。