1.安装git
yum -y install git
2.配置git的名称与邮箱地址(提交代码到gitlab需要用到)
git config --global user.name "Apex"
git config --global user.email "12345678@qq.com"
3.新建一个存放项目的文件夹
mkdir /etc/git
4.从gitlab上克隆需要的项目到项目文件夹中
cd /etc/git
git clone http://10.1.60.114:9000/gitlab-instance-c484dcfc/cs.git
![](https://img-blog.csdnimg.cn/img_convert/c58152155119398331ca7f3e829240e4.png)
![](https://img-blog.csdnimg.cn/img_convert/928edf68d338fef3cd1b41d882184b01.png)
如果本地有项目的情况下,直接从gitlab仓库拉代码更新本地仓库即可
git pull origin master
4.查看复制下来的项目
cd ./cs
ls
![](https://img-blog.csdnimg.cn/img_convert/dede984334004c3cc452c627e4bc5f4c.png)
5.查看当前分支(main分支是主分支,受到保护不能用于代码的提交)
git status
![](https://img-blog.csdnimg.cn/img_convert/dda873b095ae60353232bfa45578fcf3.png)
6.创建一个新的分支
git branch apex
7.查看当前有的分区
git branch
![](https://img-blog.csdnimg.cn/img_convert/f5dbb80591086feb6ab67d1d024896c9.png)
8.切换到新的分支
git checkout apex
![](https://img-blog.csdnimg.cn/img_convert/3b5db5b1c474d69596b49ac591d18e1e.png)
9.在当前项目下新编辑一个java文件
echo "123" > 1.java
![](https://img-blog.csdnimg.cn/img_convert/c8b3cd8d247da1684c65735f37c7987b.png)
10.提交变更到gitlab的仓库上
git add ./* #添加文件到缓存区
git commit -m "测试代码" #提交到本地仓库,-m添加描述
git push -u origin apex #提交到远程仓库
![](https://img-blog.csdnimg.cn/img_convert/c6a85e0f31ed6d6b1816200f07a32d8b.png)
11.查看gitlab
![](https://img-blog.csdnimg.cn/img_convert/bb61387e5f75739522bff2c7444f5f0e.png)
12.创建分支代码合并请求
![](https://img-blog.csdnimg.cn/img_convert/1eaad12217e744b64fc8a73235513c8d.png)
![](https://img-blog.csdnimg.cn/img_convert/1af47984d8970871120bda055f5976cc.png)
![](https://img-blog.csdnimg.cn/img_convert/4d7980bc3d204218636ed03fbc8df5b7.png)
![](https://img-blog.csdnimg.cn/img_convert/e88489ed21252c8787d698a7b657654c.png)
![](https://img-blog.csdnimg.cn/img_convert/24b1d76a707f5dabec25e9499d1082a3.png)
![](https://img-blog.csdnimg.cn/img_convert/5804894905c5f73bf92a86e03f0ce96d.png)