GitLab 项目管理

1、创建项目

项目project属于一个group组,即一般project对应一个项目中的功能模块或服务。

注意:新建项目时不要进行初始化

图片[1]-GitLab 项目管理-李佳程的个人主页
图片[2]-GitLab 项目管理-李佳程的个人主页

命令行指引

您还可以按照以下说明从计算机中上传现有文件。

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

2、将用户添加到组或项目

将用户添加到组或项目中,并指定不同的角色,可以获取不同的权限

Gitlab用户在组里面有5种不同权限:

  • Guest:可以创建issue、发表评论,不能读写版本库
  • Reporter:可以克隆代码,不能提交,QA、PM可以赋予这个权限
  • Developer:可以克隆代码、开发、提交、 push(非保护分支Protected branches),普通开发可以赋予这个权限
  • Maintainer:可以创建项目、添加tag、保护分支、添加项目成员、编辑项目,核心开发人员可以赋予这个权限
  • Owner:可以设置项目访问权限Visibility Level、删除项目、迁移项目、管理组成员,开发组组长可以赋予这个权限

在组中添加用户并指定角色

图片[3]-GitLab 项目管理-李佳程的个人主页
图片[4]-GitLab 项目管理-李佳程的个人主页

或者在项目中添加用户进行角色指定,此方式后续管理不太方便,不建议加用户到项目,建议将用户加入组

图片[5]-GitLab 项目管理-李佳程的个人主页
图片[6]-GitLab 项目管理-李佳程的个人主页

3、使用项目

3.1、在项目中新建一个测试页面

用上面创建的用户test1登录,找到项目界面,在项目中新建文件

图片[7]-GitLab 项目管理-李佳程的个人主页
图片[8]-GitLab 项目管理-李佳程的个人主页
图片[9]-GitLab 项目管理-李佳程的个人主页

3.2、在linux客户端测试clone和提交项目

图片[10]-GitLab 项目管理-李佳程的个人主页

创建一个仓库

[root@client ~]# mkdir /data
[root@client ~]# cd /data/

[root@client data]# git clone http://192.168.1.71/testgroup/testproject.git
Cloning into 'testproject'...
Username for 'http://192.168.1.71': test1
Password for 'http://test1@192.168.1.71':
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.

[root@client data]# ls -a
.  ..  testproject

[root@client data]# tree testproject/
testproject/
└── index.html

0 directories, 1 file
# 设置用户名和邮箱
[root@client data]# git config --global user.name "test1"
[root@client data]# git config --global user.email "18961236318@189.cn"
[root@client data]# cat ~/.gitconfig
[user]
	name = test1
	email = 18961236318@lijiach

# 修改项目文件
[root@client data]# cat testproject/index.html
<h1> index html v1</h1>
<h1> index html v2</h1>

[root@client testproject]# git add .
[root@client testproject]# git commit -m "v2"
[main 09e3380] v2
 1 file changed, 1 insertion(+)
[root@client testproject]# git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Username for 'http://192.168.1.71': test1
Password for 'http://test1@192.168.1.71':
Counting objects: 5, done.
Writing objects: 100% (3/3), 256 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://192.168.1.71/testgroup/testproject.git
   faab40b..09e3380  main -> main

3.3、在windows 安装 git 客户端测试clone和提交项目

https://git-scm.com/download/win
图片[11]-GitLab 项目管理-李佳程的个人主页
图片[12]-GitLab 项目管理-李佳程的个人主页

3.4、Web端验证数据

图片[13]-GitLab 项目管理-李佳程的个人主页

3.5、实现 ssh 基于key验证的 git 访问

[root@client ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:bNqGQvoo9cL8pPcjVqI2C8Rvhasn7RBWxXv+rq63EpQ root@client
The key's randomart image is:
+---[RSA 2048]----+
|    ..           |
|    ..           |
|   .  o          |
|. . .E o         |
| = .o.o S        |
|o +o+..*         |
|.=o*oo+ +        |
|.o@B=o.o .       |
| +BOo+*=+.       |
+----[SHA256]-----+
[root@client ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqMxxsB1eDitwqBMVIijAEMfFX9YGS1GykvAOQ+rw7dzShLCwkNDZo78fl0ORLsGTkyu1uNhGVs87SO9XwsqPlV7IGHdem38fAa/DPF5LgAgXsDH3lfOV4EtII23QmGg1lS5VAqDr5xSvsiHDSwh93IPnYHhxSX3StITodTy+LC/z5QiyPWGa9+lFwp1e5VUfdkdNDJ8WcjWNe3+U7yL2Vaje6o8UH7zV0HHA/CYn1fuYnXqZhKENRyW8A5cXVnUsG37RIYqi9pV1+radlO4Oi/CX2Hw1Kv5yOpmlPL2G4nWUlVPSyAoMiIvfgDI2mqglH0OPHEcAkmOFJAlhYxXWj root@client
图片[14]-GitLab 项目管理-李佳程的个人主页
图片[15]-GitLab 项目管理-李佳程的个人主页
[root@client opt]# git clone git@192.168.1.71:testgroup/testproject.git
Cloning into 'testproject'...
Warning: Permanently added '192.168.1.71' (ECDSA) to the list of known hosts.
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (6/6), done.
[root@client opt]# ll
total 0
drwxr-xr-x 3 root root 36 Dec 18 19:08 testproject

3.6、保护分支

默认master 分支被保护,开发者角色无法对被保护的分支提交代码
也可以将其它分支进行保护,防止指定分支被破环

图片[16]-GitLab 项目管理-李佳程的个人主页

3.7、合并分支

由于普通开发者无法直接提交代码至master分支,可以先创建其它分支如dev,再提交代码到dev分支,接下来申请将dev 分支合并至master分支,管理者收到请求,经过审核没有问题进行批准合并,最终实现master代码的更新。

新建分支

图片[17]-GitLab 项目管理-李佳程的个人主页
图片[18]-GitLab 项目管理-李佳程的个人主页
[root@client testproject]# git branch -m main develop
[root@client testproject]# git push origin develop
Username for 'http://192.168.1.71': test1
Password for 'http://test1@192.168.1.71':
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 262 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: To create a merge request for develop, visit:
remote:   http://192.168.1.71/testgroup/testproject/-/merge_requests/new?merge_request%5Bsource_branch%5D=develop
remote:
To http://192.168.1.71/testgroup/testproject.git
   09e3380..6627e87  develop -> develop
图片[19]-GitLab 项目管理-李佳程的个人主页
图片[20]-GitLab 项目管理-李佳程的个人主页
图片[21]-GitLab 项目管理-李佳程的个人主页
图片[22]-GitLab 项目管理-李佳程的个人主页
图片[23]-GitLab 项目管理-李佳程的个人主页
图片[24]-GitLab 项目管理-李佳程的个人主页

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享