Git克隆Github或Gitlab上非Master分支代码的方法
今天想使用一下之前开源项目Blog_mini一个分支的代码,于是把整个项目克隆下来:
xpleaf@leaf:~/test$gitclonehttps://github.com/xpleaf/Blog_mini正克隆到'Blog_mini'...remote:Countingobjects:1153,done.remote:Total1153(delta0),reused0(delta0),pack-reused1153接收对象中:100%(1153/1153),2.18MiB|238.00KiB/s,完成.处理delta中:100%(673/673),完成.检查连接...完成。
然后查看分支,发现竟然没有之前创建的分支:
xpleaf@leaf:~/test/Blog_mini$gitbranch*master
这是因为git clone命令默认就是克隆仓库中master的代码的,但是可以查看远程仓库的分支:
xpleaf@leaf:~/test/Blog_mini$gitbranch-rorigin/HEAD->origin/masterorigin/masterorigin/version_1.0xpleaf@leaf:~/test/Blog_mini$gitbranch-a*masterremotes/origin/HEAD->origin/masterremotes/origin/masterremotes/origin/version_1.0
然后再使用git checkout命令切换到自己期望的分支上:
xpleaf@leaf:~/test/Blog_mini$gitcheckoutremotes/origin/version_1.0Note:checkingout'remotes/origin/version_1.0'.Youarein'detachedHEAD'state.Youcanlookaround,makeexperimentalchangesandcommitthem,andyoucandiscardanycommitsyoumakeinthisstatewithoutimpactinganybranchesbyperforminganothercheckout.Ifyouwanttocreateanewbranchtoretaincommitsyoucreate,youmaydoso(noworlater)byusing-bwiththecheckoutcommandagain.Example:gitcheckout-b<new-branch-name>HEAD目前位于2ff197d...updateREADME.md
于是就可以看到目前已经在分支version_1.0上了,相应的代码也会克隆下来:
xpleaf@leaf:~/test/Blog_mini$gitbranch*(头指针分离于origin/version_1.0)masterxpleaf@leaf:~/test/Blog_mini$lsappLICENSEmigrationsREADME.mdrequirements.txtconfig.pymanage.pyProcfilerequirements
当然上面是用Github的例子来说明,实际上使用Gitlab或者其它自己搭的Git服务器也是可以的,因为使用的都是Git版本控制系统。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。