Git克隆Github或Gitlab上非Master分支代码的方法
2017-05-18 18:17
501 查看
今天想使用一下之前开源项目Blog_mini一个分支的代码,于是把整个项目克隆下来:
当然上面是用Github的例子来说明,实际上使用Gitlab或者其它自己搭的Git服务器也是可以的,因为使用的都是Git版本控制系统。
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_mini$ git branch * master这是因为git clone命令默认就是克隆仓库中master的代码的,但是可以查看远程仓库的分支:
xpleaf@leaf:~/test/Blog_mini$ git branch -r origin/HEAD -> origin/master origin/master origin/version_1.0 xpleaf@leaf:~/test/Blog_mini$ git 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 -b with the checkout command again. Example: git checkout -b <new-branch-name> HEAD 目前位于 2ff197d... update README.md于是就可以看到目前已经在分支version_1.0上了,相应的代码也会克隆下来:
xpleaf@leaf:~/test/Blog_mini$ git branch * (头指针分离于 origin/version_1.0) master xpleaf@leaf:~/test/Blog_mini$ ls app LICENSE migrations README.md requirements.txt config.py manage.py Procfile requirements
当然上面是用Github的例子来说明,实际上使用Gitlab或者其它自己搭的Git服务器也是可以的,因为使用的都是Git版本控制系统。
相关文章推荐
- git提交代码至GitLab或GitHub出现 src refspec master does not match any
- Git(GitHub) 003 如何 clone 非 master 分支的代码 — 切换到指定 branch分支 或者 tag版本
- Git入门: 从GitHub上克隆代码到本机
- github for mac master:git分支提交
- git切换分支保存修改的代码的方法
- git+github创建分支&提交并贡献代码
- Git+GitHub创建分支&提交并贡献代码(Linux环境)
- 不幸的问题还是出现了:Chromium代码上整理patch(working目录/master分支),部分文件做了git checkout恢复,结果GYP再编译就出错了
- [置顶] AndroidStudio中利用git下载github或者git.oschina的代码时报错:repository test has failed解决方法
- git上传本地代码到github(最简单方法,不用配置ssh)
- 【代码管理】GitHub超详细图文攻略 - Git客户端下载安装 GitHub提交修改源码工作流程 Git分支 标签 过滤 Git版本工作流
- Git、Github和Gitlab简介和使用方法
- 使用git客户端第一次git clone github.com代码的方法
- git使用命令行方式提交代码到github或gitlab上
- 本地代码提交到Git@OSC、github或其他远程仓库的方法
- 【代码管理】GitHub超详细图文攻略 - Git客户端下载安装 GitHub提交修改源码工作流程 Git分支 标签 过滤 Git版本工作流
- git切换分支保存修改的代码的方法(转载)
- 如何克隆git上的某一个分支的代码
- GIT GUI克隆github代码
- git切换分支保存修改的代码的方法