GitLab重新认识

https://blog.csdn.net/Adelly/article/details/79099772

https://blog.csdn.net/justlpf/article/details/80681332

    1. git是分布式的,svn不是
      git分布式本地就可以用,可以随便保存各种历史痕迹,不用担心污染服务器,连不上服务器也能提交代码、查看log。
    2. GIT分支和SVN的分支不同
      分支在SVN中实际上是版本库中的一份copy,而git一个仓库是一个快照,所以git 切换、合并分支等操作更快速。
    3. git有一个强大的代码仓库管理系统 - gitlab
      可以很方便的管理权限、代码review,创建、管理project

GitLab介绍

GitLab:是一个基于Git实现的在线代码仓库托管软件,你可以用gitlab自己搭建一个类似于Github一样的系统,一般用于在企业、学校等内部网络搭建git私服。
功能:Gitlab 是一个提供代码托管、提交审核和问题跟踪的代码管理平台。对于软件工程质量管理非常重要。
版本:GitLab 分为社区版(CE) 和企业版(EE)。
配置:建议CPU2核,内存2G以上。

Gitlab的服务构成:

Nginx:静态web服务器。
gitlab-shell:用于处理Git命令和修改authorized keys列表。(Ruby)
gitlab-workhorse: 轻量级的反向代理服务器。(go)

GitLab Workhorse是一个敏捷的反向代理。它会处理一些大的HTTP请求,比如文件上传、文件下载、Git push/pull和Git包下载。其它请求会反向代理到GitLab Rails应用,即反向代理给后端的unicorn。

logrotate:日志文件管理工具。
postgresql:数据库。
redis:缓存数据库。
sidekiq:用于在后台执行队列任务(异步执行)。(Ruby)
unicorn:An HTTP server for Rack applications,GitLab Rails应用是托管在这个服务器上面的。(Ruby Web Server,主要使用Ruby编写)

vi /etc/yum.repos.d/gitlab_gitlab-ce.repo

[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
yum install curl openssh-server openssh-clients postfix cronie
systemctl start postfix.service
systemctl enable postfix.service

这里安装了postfix,我自行配置了postfix。

复制代码
vim /etc/postfix/main.cf
myhostname = sample.test.com  ← 设置系统的主机名

mydomain = test.com  ← 设置域名(我们将让此处设置将成为E-mail地址“@”后面的部分)

myorigin = $mydomain  ← 将发信地址“@”后面的部分设置为域名(非系统主机名)

inet_interfaces = all  ← 接受来自所有网络的请求

mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain  ← 指定发给本地邮件的域名

home_mailbox = Maildir/  ← 指定用户邮箱目录
复制代码

#这句是用来做防火墙的,避免用户通过ssh方式和http来访问。

yum install lokkit
lokkit -s http -s ssh

yum makecache就是把服务器的包信息下载到本地电脑缓存起来
配合yum -C search xxx使用,不用上网检索就能查找软件信息

yum makecache
yum install gitlab-ce
gitlab-ctl reconfigure    #Configure and start GitLab

配置域名: vim /var/opt/gitlab/nginx/conf/gitlab-http.conf

?
1
2
3
4
# 外网访问的端口,如果服务器已经有服务器占用了80,那么这里可以改成其它
listen *:8888;
server_name gitlab. test .domain.com;
set $http_host_with_default "gitlab.test.domain.com:8888" ;

补充说明:因为编译gitlab的配置 /etc/gitlab/gitlab.rb 时会重新生成这个自定义nginx 配置,所以只要 gitlab 的配置配得好,上面的nginx其实不需要自定义的。

修改密码

gitlab-rails console production
user = User.where(id:1).first
user.password='123456'
user.save!

 

密码最少8位,上面的代码最后显示密码太短。最后提示才对

GitLab备份和恢复

备份

# 可以将此命令写入crontab,以实现定时备份
/usr/bin/gitlab-rake gitlab:backup:create

备份的数据会存储在/var/opt/gitlab/backups,用户通过自定义参数 gitlab_rails['backup_path'],改变默认值。

恢复

复制代码
# 停止unicorn和sidekiq,保证数据库没有新的连接,不会有写数据情况
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

# 进入备份目录进行恢复,1476900742为备份文件的时间戳
cd /var/opt/gitlab/backups
gitlab-rake gitlab:backup:restore BACKUP=1476900742
cd -

# 启动unicorn和sidekiq
gitlab-ctl start unicorn
gitlab-ctl start sidekiq
复制代码

GitLab配置文件修改

    vim /etc/gitlab/gitlab.rb

gitlab基本配置:

#外部访问url(经过编译后,自动将这个配置编译到nginx配置,nginx就无需配置了)
external_url 'http://gitlab.test.domain.com:8888'
#默认值就是8080。如果端口被占用,可将8080修改为其它(例如:9090)
unicorn['port'] = 8080

gitlab发送邮件配置

复制代码
gitlab_rails['smtp_enable'] = true  
gitlab_rails['smtp_address'] = “smtp.exmail.qq.com”  
gitlab_rails['smtp_port'] = 25  
gitlab_rails['smtp_user_name'] =[email protected]“  
gitlab_rails['smtp_password'] = "smtp password"  
gitlab_rails['smtp_authentication']= “plain"  
gitlab_rails['smtp_enable_starttls_auto']= true  
gitlab_rails['gitlab_email_from']= '[email protected]'  
gitlab_rails['gitlab_email_reply_to']= ‘[email protected]'
复制代码
复制代码
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "[email protected]"
gitlab_rails['smtp_password'] = "shuai,0812."
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false
复制代码
复制代码
 gitlab_rails['smtp_enable'] = true
 gitlab_rails['smtp_address'] = "smtp.qq.com"
 gitlab_rails['smtp_port'] = 465
 gitlab_rails['smtp_user_name'] = "******@qq.com"
 gitlab_rails['smtp_password'] = "授权码"
 gitlab_rails['smtp_domain'] = "smtp.qq.com"
 gitlab_rails['smtp_authentication'] = "login"
 gitlab_rails['smtp_enable_starttls_auto'] = true
 gitlab_rails['smtp_tls'] = true
 gitlab_rails['gitlab_email_from'] = '******@qq.com'
复制代码

服务器修改过ssh端口的坑(需要修改配置ssh端口)

#修改过ssh端口,gitlab中项目的的ssh地址,会在前面加上协议头和端口号“ssh://[email protected]:55725/huangdc/test.git”
gitlab_rails['gitlab_shell_ssh_port'] = 55725

配置生效

#使配置生效
gitlab-ctl reconfigure
#重新启动GitLab 
gitlab-ctl restart

GitLab常用命令

复制代码
gitlab-ctl start    # 启动所有 gitlab 组件;
gitlab-ctl stop        # 停止所有 gitlab 组件;
gitlab-ctl restart        # 重启所有 gitlab 组件;
gitlab-ctl status        # 查看服务状态;
vim /etc/gitlab/gitlab.rb        # 修改gitlab配置文件;
gitlab-ctl reconfigure        # 重新编译gitlab的配置;
gitlab-rake gitlab:check SANITIZE=true --trace    # 检查gitlab;
gitlab-ctl tail        # 查看日志;
gitlab-ctl tail nginx/gitlab_access.log
复制代码

注意:执行 reconfigure 命令会把gitlab的nginx组件的配置还原,导致自定义修改的端口以及域名等都没有了。

常用目录

    日志地址:/var/log/gitlab/   # 对应各服务的打印日志 
    服务地址:/var/opt/gitlab/   # 对应各服务的主目录 

查看gitlab版本

cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

新建项目

使用root用户登录进gitlab会后,点击“new project“创建一个项目,比如项目命名为“kuaijiFirstProject”。
然后会发现,硬盘上已经生成了一个git文件:

    /var/opt/gitlab/git-data/repositories/root/kuaijiFirstProject.git

汉化

https://gitlab.com/xhang/gitlab.git

gitlab的使用

    ssh -T -p 55725 git@gitlab.domain.com 

注意:<fornt style="color:red">以上这条 ssh 命令测试通过,未必代表就能 git clone 代码,git clone 代码需要执行命令的账户有写权限,如果是普通用户用 sudo git clone 那么 git 就会使用的 root 账号的 Private Key。 </fornt>

1.登录

管理员会为使用者开通账号并设置权限。

https://blog.csdn.net/juse__we/article/details/80361135 

https://www.cnblogs.com/wintersun/p/3930900.html

2.使用者在客户端生成ssh key

参考文章: http://www.jianshu.com/p/142b3dc8ae15

    ssh-keygen -t rsa -C "huangdc@domain.com"
复制代码
[root@localhost ~]# ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
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:5AmQFVntp/KeYDfRcjkJREuE0Jnq5wieih9HwjaxtSs [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|    .o+*.B=      |
|    ... =o..     |
|  . . ....o      |
| . + ..+ ..o.o   |
|  * o.  S oo*    |
| . +... o .+ .   |
|  E.oo +ooo      |
| . +o ...o.o     |
|..o.     .o      |
+----[SHA256]-----+
复制代码

3.将公钥的内容copy到gitlab用户设置里面的“SSH Keys”

Windows:   lip < ~/.ssh/id_rsa.pub
Mac:      pbcopy < ~/.ssh/id_rsa.pub
GNU/Linux (requires xclip):    xclip -sel clip < ~/.ssh/id_rsa.pub    #xclip只能在X程序中使用  用法: https://www.jianshu.com/p/83a22e1eda6a

4.测试ssh连接

#标准测试代码:ssh -T git@gitlab.com
ssh -T -p 55725 [email protected]  #修改过端口号的测试代码

如果连接成功的话,会出现以下信息:

    Welcome to GitLab, huangdc!

说明:实际上执行这条ssh命令,所使用的远程服务器的用户是git,这个用户是在安装gitlab的时候生成的,所有使用gitlab服务器的ssh客户端,都是使用git这个用户。在这里的用户“huangdc”是通过gitlab创建的,是用于gitlab的权限管理,也用作标识提交代码的开发者信息,不要跟ssh的用户混淆了。

如何使用多个SSH公钥(自己电脑在使用多个代码仓库)

原理其实是:因为每个仓库都需要 ssh 连接,而 ssh 命令默认是使用 .ssh 目录下面的私钥去连接代码仓库,所以我们可以在 .ssh/config 目录里面针对不同的仓库域名重定义它的私钥。

例子如下:

编辑文件: vim /Users/david/.ssh/config

    Host            gitlab.domain.com    
    IdentityFile    /Users/david/.ssh/id_rsa    

命令行环境下初始化项目

  1. 首先在 gitlab 上面创建一个空的代码仓库,得到仓库地址如下:
ssh://[email protected]:55725/huangdc/test.git
  1. 在本地初始化仓库、提交代码、推送到远程 master 分支。
复制代码
git clone ssh://[email protected]:55725/huangdc/test.git
cd test  
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
复制代码

命令行环境下迁移旧的项目

  1. 首先在 gitlab 上面创建一个空的代码仓库,得到仓库地址如下:
#注意:已存在代码的旧项目只能推送到空的远程代码仓库
ssh://[email protected]:55725/dev/memberApi.git    
  1. 本地初始化项目、关联远程仓库、推送到远程仓库
 cd /Users/david/work_www/memberApi
 git init
 git remote add origin ssh://[email protected]:55725/dev/memberApi.git
 git push -u origin master

SourceTree的安装和打开

  1. 官网下载链接:https://www.sourcetreeapp.com/
  2. 打开SourceTree之后,需要登录Atlassian账号来激活SourceTree。可以使用Google账号直接关联登录。
  3. 登录后还需要一些设置,以最简单的方式跳过就行。

Git Flow

http://flc.ren/2015/12/381.html

 

 可能出现的问题:

1.Gitlab搭建好之后,不能通过http://localhost或者http://127.0.0.1访问Gitlab的web管理端页面。

2.自定义Gitlab域名,如gitlab.abc.com

针对第一个问题,查看80端口是否被占用。修改相关配置后重启gitlab就可以访问。

第二个问题,需要修改两个文件

/etc/hosts       127.0.0.1 gitlab.abc.com

/etc/gitlab/gitlab.rb, external_url  'http://gitlab.abc.com'  

/var/opt/gitlab/gitlab-rails/etc/gitlab.yml,找到## Web server settings

将host的值改成:gitlab.abc.com  

命令行指令

全域设置
git config --global user.name "qwert123"
git config --global user.email "[email protected]"
创建一个新的存储库
git clone http://qwe.benet.com/qwert/asd.git
cd asd
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://qwe.benet.com/qwert/asd.git
git add .
git commit -m "Initial commit"
git push -u origin master
现有存储库
cd existing_repo
git remote rename origin old-origin
git remote add origin http://qwe.benet.com/qwert/asd.git
git push -u origin --all
git push -u origin --tags

https://blog.csdn.net/Adelly/article/details/79099772

https://blog.csdn.net/justlpf/article/details/80681332

    1. git是分布式的,svn不是
      git分布式本地就可以用,可以随便保存各种历史痕迹,不用担心污染服务器,连不上服务器也能提交代码、查看log。
    2. GIT分支和SVN的分支不同
      分支在SVN中实际上是版本库中的一份copy,而git一个仓库是一个快照,所以git 切换、合并分支等操作更快速。
    3. git有一个强大的代码仓库管理系统 - gitlab
      可以很方便的管理权限、代码review,创建、管理project

GitLab介绍

GitLab:是一个基于Git实现的在线代码仓库托管软件,你可以用gitlab自己搭建一个类似于Github一样的系统,一般用于在企业、学校等内部网络搭建git私服。
功能:Gitlab 是一个提供代码托管、提交审核和问题跟踪的代码管理平台。对于软件工程质量管理非常重要。
版本:GitLab 分为社区版(CE) 和企业版(EE)。
配置:建议CPU2核,内存2G以上。

Gitlab的服务构成:

Nginx:静态web服务器。
gitlab-shell:用于处理Git命令和修改authorized keys列表。(Ruby)
gitlab-workhorse: 轻量级的反向代理服务器。(go)

GitLab Workhorse是一个敏捷的反向代理。它会处理一些大的HTTP请求,比如文件上传、文件下载、Git push/pull和Git包下载。其它请求会反向代理到GitLab Rails应用,即反向代理给后端的unicorn。

logrotate:日志文件管理工具。
postgresql:数据库。
redis:缓存数据库。
sidekiq:用于在后台执行队列任务(异步执行)。(Ruby)
unicorn:An HTTP server for Rack applications,GitLab Rails应用是托管在这个服务器上面的。(Ruby Web Server,主要使用Ruby编写)

vi /etc/yum.repos.d/gitlab_gitlab-ce.repo

[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
yum install curl openssh-server openssh-clients postfix cronie
systemctl start postfix.service
systemctl enable postfix.service

这里安装了postfix,我自行配置了postfix。

复制代码
vim /etc/postfix/main.cf
myhostname = sample.test.com  ← 设置系统的主机名

mydomain = test.com  ← 设置域名(我们将让此处设置将成为E-mail地址“@”后面的部分)

myorigin = $mydomain  ← 将发信地址“@”后面的部分设置为域名(非系统主机名)

inet_interfaces = all  ← 接受来自所有网络的请求

mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain  ← 指定发给本地邮件的域名

home_mailbox = Maildir/  ← 指定用户邮箱目录
复制代码

#这句是用来做防火墙的,避免用户通过ssh方式和http来访问。

yum install lokkit
lokkit -s http -s ssh

yum makecache就是把服务器的包信息下载到本地电脑缓存起来
配合yum -C search xxx使用,不用上网检索就能查找软件信息

yum makecache
yum install gitlab-ce
gitlab-ctl reconfigure    #Configure and start GitLab

配置域名: vim /var/opt/gitlab/nginx/conf/gitlab-http.conf

?
1
2
3
4
# 外网访问的端口,如果服务器已经有服务器占用了80,那么这里可以改成其它
listen *:8888;
server_name gitlab. test .domain.com;
set $http_host_with_default "gitlab.test.domain.com:8888" ;

补充说明:因为编译gitlab的配置 /etc/gitlab/gitlab.rb 时会重新生成这个自定义nginx 配置,所以只要 gitlab 的配置配得好,上面的nginx其实不需要自定义的。

修改密码

gitlab-rails console production
user = User.where(id:1).first
user.password='123456'
user.save!

 

密码最少8位,上面的代码最后显示密码太短。最后提示才对

GitLab备份和恢复

备份

# 可以将此命令写入crontab,以实现定时备份
/usr/bin/gitlab-rake gitlab:backup:create

备份的数据会存储在/var/opt/gitlab/backups,用户通过自定义参数 gitlab_rails['backup_path'],改变默认值。

恢复

复制代码
# 停止unicorn和sidekiq,保证数据库没有新的连接,不会有写数据情况
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

# 进入备份目录进行恢复,1476900742为备份文件的时间戳
cd /var/opt/gitlab/backups
gitlab-rake gitlab:backup:restore BACKUP=1476900742
cd -

# 启动unicorn和sidekiq
gitlab-ctl start unicorn
gitlab-ctl start sidekiq
复制代码

GitLab配置文件修改

    vim /etc/gitlab/gitlab.rb

gitlab基本配置:

#外部访问url(经过编译后,自动将这个配置编译到nginx配置,nginx就无需配置了)
external_url 'http://gitlab.test.domain.com:8888'
#默认值就是8080。如果端口被占用,可将8080修改为其它(例如:9090)
unicorn['port'] = 8080

gitlab发送邮件配置

复制代码
gitlab_rails['smtp_enable'] = true  
gitlab_rails['smtp_address'] = “smtp.exmail.qq.com”  
gitlab_rails['smtp_port'] = 25  
gitlab_rails['smtp_user_name'] =[email protected]“  
gitlab_rails['smtp_password'] = "smtp password"  
gitlab_rails['smtp_authentication']= “plain"  
gitlab_rails['smtp_enable_starttls_auto']= true  
gitlab_rails['gitlab_email_from']= '[email protected]'  
gitlab_rails['gitlab_email_reply_to']= ‘[email protected]'
复制代码
复制代码
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "[email protected]"
gitlab_rails['smtp_password'] = "shuai,0812."
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false
复制代码
复制代码
 gitlab_rails['smtp_enable'] = true
 gitlab_rails['smtp_address'] = "smtp.qq.com"
 gitlab_rails['smtp_port'] = 465
 gitlab_rails['smtp_user_name'] = "******@qq.com"
 gitlab_rails['smtp_password'] = "授权码"
 gitlab_rails['smtp_domain'] = "smtp.qq.com"
 gitlab_rails['smtp_authentication'] = "login"
 gitlab_rails['smtp_enable_starttls_auto'] = true
 gitlab_rails['smtp_tls'] = true
 gitlab_rails['gitlab_email_from'] = '******@qq.com'
复制代码

服务器修改过ssh端口的坑(需要修改配置ssh端口)

#修改过ssh端口,gitlab中项目的的ssh地址,会在前面加上协议头和端口号“ssh://[email protected]:55725/huangdc/test.git”
gitlab_rails['gitlab_shell_ssh_port'] = 55725

配置生效

#使配置生效
gitlab-ctl reconfigure
#重新启动GitLab 
gitlab-ctl restart

GitLab常用命令

复制代码
gitlab-ctl start    # 启动所有 gitlab 组件;
gitlab-ctl stop        # 停止所有 gitlab 组件;
gitlab-ctl restart        # 重启所有 gitlab 组件;
gitlab-ctl status        # 查看服务状态;
vim /etc/gitlab/gitlab.rb        # 修改gitlab配置文件;
gitlab-ctl reconfigure        # 重新编译gitlab的配置;
gitlab-rake gitlab:check SANITIZE=true --trace    # 检查gitlab;
gitlab-ctl tail        # 查看日志;
gitlab-ctl tail nginx/gitlab_access.log
复制代码

注意:执行 reconfigure 命令会把gitlab的nginx组件的配置还原,导致自定义修改的端口以及域名等都没有了。

常用目录

    日志地址:/var/log/gitlab/   # 对应各服务的打印日志 
    服务地址:/var/opt/gitlab/   # 对应各服务的主目录 

查看gitlab版本

cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

新建项目

使用root用户登录进gitlab会后,点击“new project“创建一个项目,比如项目命名为“kuaijiFirstProject”。
然后会发现,硬盘上已经生成了一个git文件:

    /var/opt/gitlab/git-data/repositories/root/kuaijiFirstProject.git

汉化

https://gitlab.com/xhang/gitlab.git

gitlab的使用

    ssh -T -p 55725 git@gitlab.domain.com 

注意:<fornt style="color:red">以上这条 ssh 命令测试通过,未必代表就能 git clone 代码,git clone 代码需要执行命令的账户有写权限,如果是普通用户用 sudo git clone 那么 git 就会使用的 root 账号的 Private Key。 </fornt>

1.登录

管理员会为使用者开通账号并设置权限。

https://blog.csdn.net/juse__we/article/details/80361135 

https://www.cnblogs.com/wintersun/p/3930900.html

2.使用者在客户端生成ssh key

参考文章: http://www.jianshu.com/p/142b3dc8ae15

    ssh-keygen -t rsa -C "huangdc@domain.com"
复制代码
[root@localhost ~]# ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
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:5AmQFVntp/KeYDfRcjkJREuE0Jnq5wieih9HwjaxtSs [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|    .o+*.B=      |
|    ... =o..     |
|  . . ....o      |
| . + ..+ ..o.o   |
|  * o.  S oo*    |
| . +... o .+ .   |
|  E.oo +ooo      |
| . +o ...o.o     |
|..o.     .o      |
+----[SHA256]-----+
复制代码

3.将公钥的内容copy到gitlab用户设置里面的“SSH Keys”

Windows:   lip < ~/.ssh/id_rsa.pub
Mac:      pbcopy < ~/.ssh/id_rsa.pub
GNU/Linux (requires xclip):    xclip -sel clip < ~/.ssh/id_rsa.pub    #xclip只能在X程序中使用  用法: https://www.jianshu.com/p/83a22e1eda6a

4.测试ssh连接

#标准测试代码:ssh -T git@gitlab.com
ssh -T -p 55725 [email protected]  #修改过端口号的测试代码

如果连接成功的话,会出现以下信息:

    Welcome to GitLab, huangdc!

说明:实际上执行这条ssh命令,所使用的远程服务器的用户是git,这个用户是在安装gitlab的时候生成的,所有使用gitlab服务器的ssh客户端,都是使用git这个用户。在这里的用户“huangdc”是通过gitlab创建的,是用于gitlab的权限管理,也用作标识提交代码的开发者信息,不要跟ssh的用户混淆了。

如何使用多个SSH公钥(自己电脑在使用多个代码仓库)

原理其实是:因为每个仓库都需要 ssh 连接,而 ssh 命令默认是使用 .ssh 目录下面的私钥去连接代码仓库,所以我们可以在 .ssh/config 目录里面针对不同的仓库域名重定义它的私钥。

例子如下:

编辑文件: vim /Users/david/.ssh/config

    Host            gitlab.domain.com    
    IdentityFile    /Users/david/.ssh/id_rsa    

命令行环境下初始化项目

  1. 首先在 gitlab 上面创建一个空的代码仓库,得到仓库地址如下:
ssh://[email protected]:55725/huangdc/test.git
  1. 在本地初始化仓库、提交代码、推送到远程 master 分支。
复制代码
git clone ssh://[email protected]:55725/huangdc/test.git
cd test  
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
复制代码

命令行环境下迁移旧的项目

  1. 首先在 gitlab 上面创建一个空的代码仓库,得到仓库地址如下:
#注意:已存在代码的旧项目只能推送到空的远程代码仓库
ssh://[email protected]:55725/dev/memberApi.git    
  1. 本地初始化项目、关联远程仓库、推送到远程仓库
 cd /Users/david/work_www/memberApi
 git init
 git remote add origin ssh://[email protected]:55725/dev/memberApi.git
 git push -u origin master

SourceTree的安装和打开

  1. 官网下载链接:https://www.sourcetreeapp.com/
  2. 打开SourceTree之后,需要登录Atlassian账号来激活SourceTree。可以使用Google账号直接关联登录。
  3. 登录后还需要一些设置,以最简单的方式跳过就行。

Git Flow

http://flc.ren/2015/12/381.html

 

 可能出现的问题:

1.Gitlab搭建好之后,不能通过http://localhost或者http://127.0.0.1访问Gitlab的web管理端页面。

2.自定义Gitlab域名,如gitlab.abc.com

针对第一个问题,查看80端口是否被占用。修改相关配置后重启gitlab就可以访问。

第二个问题,需要修改两个文件

/etc/hosts       127.0.0.1 gitlab.abc.com

/etc/gitlab/gitlab.rb, external_url  'http://gitlab.abc.com'  

/var/opt/gitlab/gitlab-rails/etc/gitlab.yml,找到## Web server settings

将host的值改成:gitlab.abc.com  

命令行指令

全域设置
git config --global user.name "qwert123"
git config --global user.email "[email protected]"
创建一个新的存储库
git clone http://qwe.benet.com/qwert/asd.git
cd asd
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://qwe.benet.com/qwert/asd.git
git add .
git commit -m "Initial commit"
git push -u origin master
现有存储库
cd existing_repo
git remote rename origin old-origin
git remote add origin http://qwe.benet.com/qwert/asd.git
git push -u origin --all
git push -u origin --tags

猜你喜欢

转载自www.cnblogs.com/cs2612109/p/10827709.html