温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Git克隆Github或Gitlab上非Master分支代码的方法

发布时间:2020-07-26 03:40:45 阅读:11772 作者:xpleaf 栏目:开发技术
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

    今天想使用一下之前开源项目Blog_mini一个分支的代码,于是把整个项目克隆下来:

xpleaf@leaf:~/test$ git clone https://github.com/xpleaf/Blog_mini
正克隆到 'Blog_mini'...
remote: Counting objects: 1153, done.
remote: Total 1153 (delta 0), reused 0 (delta 0), pack-reused 1153
接收对象中: 100% (1153/1153), 2.18 MiB | 238.00 KiB/s, 完成.
处理 delta 中: 100% (673/673), 完成.
检查连接... 完成。

    然后查看分支,发现竟然没有之前创建的分支:

xpleaf@leaf:~/test/Blog_minigit branch 
* master

    这是因为git clone命令默认就是克隆仓库中master的代码的,但是可以查看远程仓库的分支:

xpleaf@leaf:~/test/Blog_minigit branch -r
  origin/HEAD -> origin/master
  origin/master
  origin/version_1.0
xpleaf@leaf:~/test/Blog_minigit branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/version_1.0

    然后再使用git checkout命令切换到自己期望的分支上:

xpleaf@leaf:~/test/Blog_mini$ git checkout remotes/origin/version_1.0
Note: checking out 'remotes/origin/version_1.0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -with the checkout command again. Example:

  git checkout -<new-branch-name>

HEAD 目前位于 2ff197d... update README.md

    于是就可以看到目前已经在分支version_1.0上了,相应的代码也会克隆下来:

xpleaf@leaf:~/test/Blog_minigit branch 
* (头指针分离于 origin/version_1.0)
  master
xpleaf@leaf:~/test/Blog_minils
app        LICENSE    migrations  README.md     requirements.txt
config.py  manage.py  Procfile    requirements

    当然上面是用Github的例子来说明,实际上使用Gitlab或者其它自己搭的Git服务器也是可以的,因为使用的都是Git版本控制系统。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×