22.13 搭建git服务器

可莉
• 阅读 586

22.13 搭建git服务器

**前言:**github毕竟是公开的,而私有仓库又得花钱买。所以我们可以想办法搭建一个私有的,只自己公司使用的。Gitlab是个不错的选择。在介绍它之前,先讲述一下命令行的git服务器

  • 找一台服务器,首先要安装git;

  • yum install -y git

  • 添加git用户,并且设置shell为/usr/bin/git-shell,目的是为了不让git用户远程登陆

  • useradd -s /usr/bin/git-shell git

  • cd /home/git

  • 创建authorized_keys文件,并更改属主、属组和权限,用来存客户端机器上的公钥

  • mkdir .ssh

  • touch .ssh/authorized_keys

  • chown -R git.git .ssh

  • chmod 600 .ssh/authorized_keys

  • 定好存储git仓库的目录,比如 /data/gitroot

  • mkdir /data/gitroot

  • cd /data/gitroot

  • git init --bare sample.git // 会创建一个裸仓库,裸仓库没有工作区,因为服务器上的Git仓库纯粹是为了共享,所以不让用户直接登录到服务器上去改工作区,并且服务器上的Git仓库通常都以.git结尾

  • chown -R git.git sample.git

  • 以上操作是在git服务器上做的,平时git服务器是不需要开发人员登录修改代码的,它仅仅是充当着一个服务器的角色,就像github一样,平时操作都是在我们自己的pc上做的

  • 首先要把客户端上的公钥放到git服务器上/home/git/.ssh/authorized_keys文件里

  • 在客户端上(自己pc)克隆远程仓库

  • git clone git@ip:/data/gitroot/sample.git

  • 此时就可以在当前目录下生成一个sample的目录,这个就是我们克隆的远程仓库了。进入到这里面,可以开发一些代码,然后push到远程。

    [root@3clone ~]# rpm -qa |grep git net-tools-2.0-0.17.20131004git.el7.x86_64 linux-firmware-20160830-49.git7534e19.el7.noarch crontabs-1.11-6.20121102git.el7.noarch [root@3clone ~]# yum install -y git ##安装git; Complete! [root@3clone ~]# useradd -s /usr/bin/git-shell git ##创建用户git,并-s指定其登录脚本为git-shell 不允许其登录; [root@3clone ~]# tail -n1 /etc/passwd git:x:1000:1000::/home/git:/usr/bin/git-shell [root@3clone ~]# cd /home/git/ ##进入到git用户家目录下,创建密钥文件; [root@3clone git]# mkdir .ssh [root@3clone git]# touch .ssh/authorized_keys [root@3clone git]# chown -R git:git .ssh/ [root@3clone git]# chmod 600 .ssh/authorized_keys [root@3clone git]# vim .ssh/authorized_keys ##将客户端的公钥写入到里面;和github是类似的。 [root@3clone git]# mkdir /data/gitroot ##创建仓库文件夹,并修改所属组和所属主;然后初始化仓库! [root@3clone git]# cd /data/gitroot [root@3clone gitroot]# git init --bare sample.git Initialized empty Git repository in /data/gitroot/sample.git/ [root@3clone gitroot]# chown -R git:git sample.git/

客户端60.11进行测试:

[root@Dasoncheng tmp]# git clone git@192.168.60.13:/data/gitroot/sample.git  ##克隆仓库,注意路径正确;
Cloning into 'sample'...
warning: You appear to have cloned an empty repository.
[root@Dasoncheng tmp]# cd sample/  ##进入仓库里面;
[root@Dasoncheng sample]# git branch   ##注意到这里了没有,并没有显示分支信息
[root@Dasoncheng sample]# cp /etc/fstab .
[root@Dasoncheng sample]# git add .
[root@Dasoncheng sample]# git commit -m "add a new repository"  ##尝试提交一个文件;
[master (root-commit) 633c863] add a new repository
 1 file changed, 11 insertions(+)
 create mode 100644 fstab
[root@Dasoncheng sample]# 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)

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'git@192.168.60.13:/data/gitroot/sample.git'
##这里被警告了:主要是没有上传的确认分支!
[root@Dasoncheng sample]# git push origin master  ##这里指定分支master;
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 504 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.60.13:/data/gitroot/sample.git
 * [new branch]      master -> master
[root@Dasoncheng sample]# echo aaa >a.txt  ##试一试再次推送更新;
[root@Dasoncheng sample]# git add a.txt
[root@Dasoncheng sample]# git commit -m "add a.txt"
[master 457cc84] add a.txt
 1 file changed, 1 insertion(+)
 create mode 100644 a.txt
[root@Dasoncheng sample]# git push
……
To git@192.168.60.13:/data/gitroot/sample.git
   633c863..457cc84  master -> master
##这里就上传成功了,不需要再次指定分支了;

测试完成之后,接下来呢 就可以在自己pc上面克隆repository然后共同编辑了哦!

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
前端尾随者 前端尾随者
2年前
sourceTree 添加 ssh key 方法
1.使用git客户的生成公私钥:id\rsa、id\rsa.pub1.1设置Git的username和email:$gitconfigglobaluser.name"xxx"$gitconfig\globaluser.email"xxx.mail@xxx.com"1.2.生成SSH密钥过程:1.2.1.检查是不是已经存在密钥(
Jacquelyn38 Jacquelyn38
2年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Wesley13 Wesley13
2年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
2年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
2年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
2年前
Ubutun 16.04安装git服务器
GitHub就是一个免费托管开源代码的远程仓库。既不想公开源代码,又舍不得给GitHub交保护费,那就只能自己搭建一台Git服务器作为私有仓库使用。本文演示如何使用Ubutun16.04搭建一台git服务器。搭建之前建议先aptgetupdate一下,可以避免一些错误。安装并配置gitsudoaptgeti
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
3个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这