为什么我的'git分支'没有主人? [英] Why does my 'git branch' have no master?
问题描述
我是git新手,我一直在阅读关于主分支的内容。 主人只是人们使用的传统名称,或者它具有像 HEAD
?
等特殊含义。当我在我拥有的克隆上做 git branch
,我只看到1个单独的分支 - 我正在使用的分支。根本没有主人。如果我输入 git checkout master
(正如我在很多教程或指南中看到的那样),我得到
错误:pathspec'master'与git已知的任何文件都不匹配。
我只是混淆了为什么我的克隆没有所有人似乎都暗示它总是存在。
大多数Git仓库使用 master
作为主(和默认)分支 - 如果你通过 git init
初始化一个新的Git仓库,它将有<$ c
然而,如果你克隆一个版本库,你的默认分支就是远程的 HEAD
指向( HEAD
实际上是指向分支名称的符号引用)。因此,如果您克隆的存储库中有 HEAD
指向 foo
,那么您的克隆将只有一个 foo
分支。
您从克隆的远程可能仍有 master
分支(你可以用 git ls-remote origin master
来检查),但是默认情况下你不会创建该分支的本地版本,因为 git clone
只检出远程的 HEAD
。
I'm a git newbie and I keep reading about a "master" branch. Is "master" just a conventional name that people used or does it have special meaning like HEAD
?
When I do git branch
on the clone that I have, I only see 1 single branch - the one I'm on. No "master" at all. If I type git checkout master
(as I see in alot of tutorials or guides), I get
error: pathspec 'master' did not match any file(s) known to git.
I'm just confused as to why my clone doesn't have a master
that everyone seems to imply that it always exists.
Most Git repositories use master
as the main (and default) branch - if you initialize a new Git repo via git init
, it will have master
checked out by default.
However, if you clone a repository, the default branch you have is whatever the remote's HEAD
points to (HEAD
is actually a symbolic ref that points to a branch name). So if the repository you cloned had a HEAD
pointed to, say, foo
, then your clone will just have a foo
branch.
The remote you cloned from might still have a master
branch (you could check with git ls-remote origin master
), but you wouldn't have created a local version of that branch by default, because git clone
only checks out the remote's HEAD
.
这篇关于为什么我的'git分支'没有主人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!