上一篇文章介绍了把开源项目上传到github,这篇介绍一下怎么拉取远程分支到本地;
为什么要拉取分支而不是主干呢?因为现在的项目规模越来越大,越来越复杂,一个人已经越来越难完成一个项目的开发与维护,必须依赖团队开发,团队开发也就意味着项目和团队的管理,面临着代码的合并与冲突,而拉取分支是管理团队和代码比较有效的手段;
流程
1.在本地创建一个github仓库
现在本地建一个空文件夹

然后右键打开git命令行

输入命令git init

成功后可以在刚才的文件夹里发现半透明的.git文件夹,如果没有请设置显示隐藏文件

2.建立远程连接
我们先要去github项目主页找到该项目的http地址,复制地址

然后在命令行中输入:git remote add origin https://xxxxxxxxxxxx

这样,本地仓库就和远程仓库互相关联起来了
3.拉取远程分支到本地
在项目主页找到一个叫master并且带有下箭头的地方,点开他,就可以看到在Branches栏你的项目有哪些分支

其中master是主干,我以上图中 feature/FAR-912-fcs-app-ro 分支为例,把他拉取到本地;
首先输入命令git fetch origin [远程分支名],把分支关联到仓库,那么完整的命令就是git fetch origin feature/FAR-912-fcs-app-ro

这一步有一个下载过程,项目已经下载下来了,但我们本地的仓库还是空的,那么执行最后一步拉取分支到本地:git pull origin [远程分支名称],远程分支名还是天上我们刚才的分支名,就有git pull origin feature/FAR-912-fcs-app-ro

这步走完就成功了,然后看看自己刚才在本地创建的仓库,发现项目已经有了

网友评论