一、GitLab介绍
GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,提供了Web界面用于访问公开或私有的项目。GitLab的优势如下:
- 开源免费
- 可以作为Git代码仓库
- 提供了Web界面便于管理
- 支持离线提交
- 安全性高,可针对不同用户设置不同的权限,支持不同用户只能访问特定的代码
二、GitLab安装
2.1 安装前准备
配置好主机名以及对应的域名解析,ssh远程连接,镜像仓库。
2.2 安装
#基于Ubuntu 20.04
#下载软件包
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/focal/main/g/gitlab-ce/gitlab-ce_15.5.6-ce.0_amd64.deb
#安装
dpkg -i gitlab-ce_15.5.6-ce.0_amd64.deb
2.3 GitLab初始化配置
注:GitLab相关目录
/etc/gitlab #配置文件目录
/run/gitlab #运行目录,存放数据库文件
/opt/gitlab #安装目录
/var/opt/gitlab #数据目录,源代码就存放在此目录
/var/log/gitlab #日志目录
打开/etc/gitlab/gitlab.rb,做如下配置:
external_url 'http://gitlab.xxx.com'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "3304955767@qq.com"
gitlab_rails['smtp_password'] = "udyjbaxigmgcchgb"
gitlab_rails['smtp_domain'] = "qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = "3304955767@qq.com"
#增加如下内容,给root用户指定密码才能登录
gitlab_rails['initial_root_password'] = '12345678'
2.4 名称解析
打开/etc/hosts,做如下配置:
192.168.1.103 gitlab.xxx.com
2.5 初始化服务
#每次修改完配置文件都要执行此操作
gitlab-ctl reconfigure
#查看GitLab是否启动完成
gitlab-ctl status

三、GitLab基本操作
3.1 root登录

3.2 关闭账号注册功能

四、GitLab用户和组管理
4.1 用户管理
创建用户并登录


4.2 创建组

4.3 将用户添加到组

五、项目管理
5.1 创建新项目

5.2 提交代码
#全局设置
git config --global user.name "xxx"
git config --global user.email xxx@qq.com
#克隆一个git仓库到本地
git clone "远程仓库名"
#创建dev分支
git branch dev
#新创建一些目录&文件
mkdir test
cd test && touch b.txt
#添加文件到暂存区
git add .
#提交暂存区文件到本地仓库
git commit -m "2nd initial"
#建立远程仓库与本地origin仓库关联
git remote add origin "远程仓库名"
#将当前分支推送到远程dev分支
git push -u origin dev
#新创建master分支,再切换到master分支并合并dev分支
git branch master
git checkout master
git merge dev
#推送所有分支
git push -u origin --all

