900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 还怕Github被墙?项目团队开发必备技能!

还怕Github被墙?项目团队开发必备技能!

时间:2022-10-07 00:51:17

相关推荐

还怕Github被墙?项目团队开发必备技能!

项目团队开发之从自建GitLab仓库服务器到熟练使用

0.导语

最近在做一个大项目,代码量非常大,需要一个代码库存放,而现有的Github、GitLab不适合存放私密的代码,于是自建代码服务器,存放代码,于是今天这篇文章应任而生!

本次构建采用GitLab搭建与部署,并进行代码上传与下载的测试,以供团队开发!

下面所有的部署于Ubuntu18.04!

1.如何安装?

安装一些ssh、邮件等服务!

sudo apt-get install curl openssh-server postfix ca-certificates

接下来就是安装我们的gitlab-ca,对于这个有两种方案:

第一:从下面链接下载,然后用dpkg进行安装!

https://mirrors.tuna./gitlab-ce/ubuntu/pool/trusty/main/g/gitlab-ce/

第二:直接在线安装!

这里推荐这种方案!

首先添加信任 GitLab 的 GPG 公钥:

curl /gpg.key 2> /dev/null | sudo apt-key add - &>/dev/null

配置清华源镜像路径:

vi /etc/apt/sources.list.d/gitlab-ce.list

并把下面链接写入进去:

deb https://mirrors.tuna./gitlab-ce/ubuntu xenial main

如果是其他系统,可以进入下面链接,选择:

https://mirror.tuna./help/gitlab-ce/

开始安装:

sudo apt-get update

sudo apt-get install gitlab-ce

到这里,或许你会看到下面成功的页面,但或许又是另一个场面,如下面成功与失败场面:

成功

失败

如果失败了,解决方法为:修改用户与组,打开配置文件:

sudo vi /etc/gitlab/gitlab.rb

修改为:

user['username']="gitlab"

user['group']="gitlab"

下面操作不管是不是失败都得执行!还是继续这个配置文件修改,找到external_url,需要修改为http://localhost,至于端口加不加看自己。

然后再次重新配置:

sudo gitlab-cli reconfigure

最后看到如下页面即可成功:

启动gitlab服务:

sudo gitlab-ctl start

浏览器输入:localhost

2.如何使用?

2.1上传仓库

下面来测试一下如何上传代码到仓库中:

首先创建文件夹,并初始化git。

light@city:~$ mkdir tet

light@city:~$ cd test/

light@city:~/test$ git init

已初始化空的 Git 仓库于 /home/light/test/.git/

创建一些文件:

light@city:~/test$ cat readme.md

light@city:~/test$ echo "test" >> readme.md

light@city:~/test$ cat readme.md

test

提交刚才的test项目:

light@city:~/test$ git add .

light@city:~/test$ git commit -m "test"

[master (根提交) 1f50c4b] test

1 file changed, 1 insertion(+)

create mode 100644 readme.md

light@city:~/test$ git remote add origin gitlab@192.168.100.188:root/test.git

light@city:~/test$ git push origin master

对象计数中: 3, 完成.

写入对象中: 100% (3/3), 212 bytes | 212.00 KiB/s, 完成.

Total 3 (delta 0), reused 0 (delta 0)

remote:

remote: The private project root/test was successfully created.

remote:

remote: To configure the remote, run:

remote: git remote add origin gitlab@localhost:root/test.git

remote:

remote: To view the project, visit:

remote: http://localhost/root/test

remote:

To 192.168.100.188:root/test.git

* [new branch] master -> master

可以看到上面提交成功,下面看一下服务器上是否有刚才提交的代码。

可以发现成功了!

2.2 下载仓库

直接git clone ,通过刚才安装时候配置的用户@ip地址:root/仓库名.git。

light@city:~$ git clone gitlab@192.168.100.188:root/test.git

正克隆到 'test'...

remote: Enumerating objects: 3, done.

remote: Counting objects: 100% (3/3), done.

remote: Total 3 (delta 0), reused 0 (delta 0)

接收对象中: 100% (3/3), 完成.

3.卸载

最后,如果想卸载gitlab,可以通过下面方法:

sudo apt-get remove gitlab-ca

删除所有gitlab相关的数据目录:

rm -rf /opt/gitlab

rm -rf /etc/gitlab

rm -rf /var/log/gitlab

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。