为什么我可以克隆主存储库而不是分支?

时间:2013-10-31 17:40:07

标签: git git-branch git-clone

我在github上有一个存储库的分支我正在尝试克隆。我可以在网址https://github.com/pmyusername/myrepository克隆主存储库(因为数据是私有的,所以不是实际链接)。但是,我无法克隆位于https://github.com/myusername/myrepository/tree/branchname的分支。要克隆存储库,我只需要运行:

git clone https://github.com/myusername/myrepository

但如果我尝试跑:

https://github.com/myusername/myrepository/tree/branchname

我收到错误:

fatal: repository 'https://github.com/myusername/myrepository/tree/branchname' not found

但我知道它存在是因为我正在从网址复制并粘贴它。这个问题可能与我付钱以保持私密性这一事实有关,但我不这么认为。有没有人有任何想法?

2 个答案:

答案 0 :(得分:2)

我会尝试将所有评论汇总成简洁的回复......
第1步:git clone https://github.com/myusername/myrepository
第2步:git fetch
第3步:git checkout -b desired_branch#将origin / desired_branch添加到命令行末尾以设置远程跟踪

更新:
刚刚对daniellarsson的建议做了一个快速的实验,它看似起作用:
i:work> git clone -b metro git@github.com:user/project.git
i:work> cd project
I:\work\project> git branch -a
* metro
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/metro

答案 1 :(得分:0)

如果您使用像GitEx这样的用户界面,则可以在出现的对话框中提及要克隆的分支。这将克隆回购,并自动检出分支。

enter image description here

相关问题