GitLab - 一些基础使用

1 - GitLab角色权限

1.1 组(同一组成员的行为权限)

  • 管理员创建不同的分组,然后设定分组的负责人(Owner)
  • Owner可以添加组员,为组创建项目,指定项目的负责人
  • 项目负责人可以添加项目成员并设定对应的级别

组中的角色与权限

  • Guest - 访客:可以创建issue、发表评论,不能读写版本库
  • Reporter - 报告者: QA、PM等,可以克隆代码,不能提交
  • Developer - 开发者: RD,可以克隆代码、开发、提交、push
  • Master - 主人:核心RD负责人,负责对Master分支进行维护,可以创建项目、添加tag、保护分支、添加项目成员、编辑项目
  • Owner - 拥有者: RD Leader,设置项目可见度、删除项目、迁移项目、管理组成员

角色对应的权限

1.2 项目(可见度,项目的访问权限)

  • Private - 私有,只有属于该项目的成员才能查看、拉取代码
  • Internal - 内部,可以被任何登录的用户查看、拉取代码
  • Public - 公开,任何人都可以查看、拉取代码

2 - 创建组和项目

2.1 创建组

只有管理员账户才可以创建群组(Group),创建时,一般默认是私有组,管理员是Owner。


添加组成员

2.2 创建项目

在组的页面,点击“新建项目”,有三种创建项目的方式

  • Blank project:创建一个空项目
  • Create from template:创建模板项目
  • Import project:从其他代码库导入项目

以新建空白项目为例:

3 - 本地Git配置

3.1 连接验证

特别注意:必须通过GitLab连接验证,才可以拉取和提交代码

GitLab默认提供SSH和HTTP两种方式拉取代码

  • SSH:将常用的本地开发环境的SSH公钥复制到GitLab用户配置中,无需输入用户名和代码
  • HTTP方式:直接使用用户名和密码,但每次都要重新输入
Anliven@Anliven-PC /d/Project                                          
λ ssh-keygen -t rsa -C "anliven@126.com" -b 4096                       
Generating public/private rsa key pair.                                
Enter file in which to save the key (/c/Users/Anliven/.ssh/id_rsa):    
Created directory '/c/Users/Anliven/.ssh'.                             
Enter passphrase (empty for no passphrase):                            
Enter same passphrase again:                                           
Your identification has been saved in /c/Users/Anliven/.ssh/id_rsa.    
Your public key has been saved in /c/Users/Anliven/.ssh/id_rsa.pub.    
The key fingerprint is:                                                
SHA256:sMAcpgAoRuKYZOTXBVJatSkrJ/as8sYh/T+nnVrHUMg anliven@126.com     
The key's randomart image is:                                          
+---[RSA 4096]----+                                                    
|O= .++oo         |                                                    
|X+ ==.. + .      |                                                    
|=o.o+o.o E .     |                                                    
|  .  .oo  .      |                                                    
|  .+ o. S.       |                                                    
| ..o*     o      |                                                    
|  o oo   . o     |                                                    
| . o.. .o.o      |                                                    
|  +o  .+=o       |                                                    
+----[SHA256]-----+                                                    
Anliven@Anliven-PC /d/Project
λ
Anliven@Anliven-PC /d/Project
λ  cat /c/Users/Anliven/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDQSFpwR9eBCTKfTbPEE8TWIo75KfX3AczpXK6nTKGH248pxjfq7cDe2cGj1VOSqknMqvg0g1LLiXrgbIGbtclt49UKSFXxWnVm04rZHVsz9rtfzxuF/NmSqSv7isYLZvwaI4aGXkLwILOemqwCbPRybGlkIiU9sgFK6m5gBWpsA6WqbHGlll8o1jC1cIuiPcJuYwod4+ehI5GvH3Tr3rUjkWy0QEhFfV22Nt79mJ3D+xDpDP/SxhPtPWw1Ob1+10+0+xvSTvGR/gcLUnUXciIooJVSypTPLnGe+d4Y5i+jCzDRIxeXBEQrQXafoxTjPNMb/T84mkPH+MSSTnvAk6Oelcs9MJLDIlXcDGSKXSzl2XmjjiTglq0R5gnRtUL6jxcyR0Db5mEF5maumfyKz58/O5pSDGVRW13O6V0YGq6j8f5mcn8h1usdqabbirUGA5+7OB2Ek4KlLy/U6GkHtr5gY4zch08A8/xWowGppOjb8b/MqxJuLmQY1+vvUlupALd6nNmacugmlZK+ZsheTCJhdNHLBVl40b4UZdbD19LCI5cFonvJP979J4SIc8gHh7SXu7lSTRWciA0BKLrwhhHID1PHnF5o0re4kENZW4LYiXhBo998+7TtXiK+itnjUsfHRDPUvQC0OrhmLf/DAyanpRs65rXFONEaVGf4NS+PCQ== anliven@126.com
Anliven@Anliven-PC /d/Project
λ


3.2 添加README文件

在项目界面,根据提示添加README文件后,左侧会出现“仓库”功能

3.3 受保护的分支

新创建的项目默认会把master分支设置为“受保护的分支”,只有项目的Owner和Master才有权限直接向受保护的分支提交代码。

  • 后期项目开发时,可以创建普通的Develop分支,从而以Developer角色进行代码提交
  • 创建merge request请求,在项目Owner和Master进行代码审查无误后,将代码合并到master分支
  • 创建分支时,必须填写分支名称、从哪个分支、标签或具体的提交号拉出来

4 - 本地项目的Git配置

4.1 命令行指引

在项目页面,可以在“命令行指引”部分查看到配置方法

# Git 全局设置
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
# 创建一个新仓库
git clone http://192.168.16.102/testgroup/testproject.git
cd testproject
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
# 推送现有文件夹
cd existing_folder
git init
git remote add origin http://192.168.16.102/testgroup/testproject.git
git add .
git commit -m "Initial commit"
git push -u origin master
# 推送现有的 Git 仓库
cd existing_repo
git remote rename origin old-origin
git remote add origin http://192.168.16.102/testgroup/testproject.git
git push -u origin --all
git push -u origin --tags

4.2 Git本地用户配置示例

Anliven@Anliven-PC /d/Project
λ git config --global user.name "user01"
Anliven@Anliven-PC /d/Project
λ  git config --global user.email "anliven@126.com"
Anliven@Anliven-PC /d/Project
λ 
Anliven@Anliven-PC /d/Project
λ git config --list
core.symlinks=false
core.autocrlf=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=/ssl/certs/ca-bundle.crt
diff.astextplain.textconv=astextplain
rebase.autosquash=true
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
credential.helper=manager
user.name=user01
user.email=anliven@126.com
Anliven@Anliven-PC /d/Project
λ
Anliven@Anliven-PC /d/Project
λ 

4.3 拉取及提交代码示例

Anliven@Anliven-PC /d/Project
λ git clone http://192.168.16.102/testgroup/testproject.git
Cloning into 'testproject'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
Anliven@Anliven-PC /d/Project
λ ll
total 0
drwxr-xr-x 1 Anliven 197121 0 十一 28 00:05 testproject/
Anliven@Anliven-PC /d/Project
λ echo "hello" >> testproject/README.md
Anliven@Anliven-PC /d/Project
λ cd testproject/
Anliven@Anliven-PC /d/Project/testproject (master)
λ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
        modified:   README.md
no changes added to commit (use "git add" and/or "git commit -a")
Anliven@Anliven-PC /d/Project/testproject (master)
λ git add *
warning: LF will be replaced by CRLF in README.md.
The file will have its original line endings in your working directory
Anliven@Anliven-PC /d/Project/testproject (master)
λ git commit -m "test 002"
[master 6693ace] test 002
 1 file changed, 1 insertion(+), 1 deletion(-)
Anliven@Anliven-PC /d/Project/testproject (master)
λ 
Anliven@Anliven-PC /d/Project/testproject (master)
λ git push -u origin master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 251 bytes | 251.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://192.168.16.102/testgroup/testproject.git
   defc521..6693ace  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
Anliven@Anliven-PC /d/Project/testproject (master)
λ

5 - 项目配置Webhook

在GitLab的代码库配置Webhook以及对应的触发事件。

代码库界面--》Settings --》Webhooks配置页面,填写URL和选择Trigger,单击Add webhook完成添加

Admin管理界面 --》 Settings --》Network --》Outbound requests --》勾选 Allow requests to the local network from webhooks and integrations --》保存配置

代码库界面--》Settings --》Webhooks配置页面,最下方部分可以查看模拟触发已添加的Webhook,也可以看到模拟触发的webhook的数据类型和结构

posted @ 2019-11-29 23:56  Anliven  阅读(2112)  评论(0编辑  收藏  举报