引言
Git是一个开源的分布式版本控制系统,gitlab是一个可以托管各种git库的站点。
git
git安装
- 安装Git 2.13 点击下载
-
安装github-desktop(git的可视化管理程序) 点击下载
- 在电脑上选择一个用作为仓库的目录
- 右键->Git Bash here
- 2、在bash中输入下面命名(邮箱替换成自己的)
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
- 3、出现下面提示按回车
Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter]
- 4、继续回车 查看更多详情
Enter passphrase (empty for no passphrase): [Type a passphrase] Enter same passphrase again: [Type passphrase again]
-
5、增加一步: cat ~/.ssh.id_rsa.pub
把打印出来的证书, copy 到gitlab的用户管理-> sshKey管理中去
git 常用命令
- 查看远程仓库地址名称
git remote -v
- 删掉原来git源
git remote remove origin
- 将新源地址写入本地版本库配置文件
git remote add origin [YOUR NEW .GIT URL]
- 提交所有代码到本地仓库
git commit -m "fix"
- 提交所有代码到远程仓库
git push -u origin --all
- 将远程分支映射到本地命名为local-branchname 的一分支
git checkout -b local-branchname origin/remote_branchname
gitlab 工作流
gitlab-flow是gitlab使用的基本准则,gitlab的使用过程中有主分支和从分支的概率,主分子一般命名为master或develop,开发者要新增一个功能的时候,一般会新建一个从分支(一般命名规则为 feature-xxx)
- master:功能稳定的分支
- develop:开发时候的主要分支
- feature:个人开发时候的从分支(新增功能时候建立从分支,从分支合并到develop后要把改分支删除,以免越积越多)
git && gitlab完整使用流程
- 1、创建分支
- 2、修改、提交代码
- 3、功能完成后分支请求合并
-
4、管理者review代码后接受合并
-
5、删除该功能分支