Git 服务器搭建

目录

1、安装Git

2、创建证书登录

3、初始化Git仓库

4、克隆仓库


上一章节中我们远程仓库使用了 Github,Github 公开的项目是免费的,2019 年开始 Github 私有存储库也可以无限制使用。

当然我们也可以自己搭建一台 Git 服务器作为私有仓库使用。

接下来我们将以 Centos 为例搭建 Git 服务器。

1、安装Git

复制代码
$ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel

$ yum install git

接下来我们 创建一个git用户组和用户,用来运行git服务:

复制代码
$ groupadd git

$ useradd git -g git

2、创建证书登录

收集所有需要登录的用户的公钥,公钥位于id_rsa.pub文件中,把我们的公钥导入到/home/git/.ssh/authorized_keys文件里,一行一个。

如果没有该文件创建它:

复制代码
$ cd /home/git/

$ mkdir .ssh

$ chmod 755 .ssh

$ touch .ssh/authorized_keys

$ chmod 644 .ssh/authorized_keys

3、初始化Git仓库

首先我们选定一个目录作为Git仓库,假定是/home/gitrepo/runoob.git,在/home/gitrepo目录下输入命令:

复制代码
$ cd /home

$ mkdir gitrepo

$ chown git:git gitrepo/

$ cd gitrepo
$ git init --bare runoob.git

Initialized empty Git repository in /home/gitrepo/runoob.git/

以上命令Git创建一个空仓库,服务器上的Git仓库通常都以.git结尾。然后,把仓库所属用户改为git:

复制代码
$ chown -R git:git runoob.git

4、克隆仓库

复制代码
$ git clone [email protected]:/home/gitrepo/runoob.git

Cloning into 'runoob'...

warning: You appear to have cloned an empty repository.

Checking connectivity... done.

192.168.45.4 为 Git 所在服务器 ip ,你需要将其修改为你自己的 Git 服务 ip。

这样我们的 Git 服务器安装就完成。

相关推荐
belldeep11 小时前
如何阅读、学习 Git 核心源代码 ?
git·学习·源代码
我不是秃头sheep12 小时前
Git安装教程及常用命令
git
sduwcgg20 小时前
git经验
git
麻雀无能为力20 小时前
git的使用
git
算法歌者1 天前
Visual Studio 项目 .gitignore 文件指南
git·visual studio
江边垂钓者1 天前
git cherry-pick和git stash命令详解
git
Lw老王要学习1 天前
Linux架构篇、第五章git2.49.0部署与使用
linux·运维·git·云计算·it
爱学习的张哥1 天前
专栏项目框架介绍
git·fpga开发·udp·ddr·gt收发器
Aric_Jones1 天前
lua入门语法,包含安装,注释,变量,循环等
java·开发语言·git·elasticsearch·junit·lua
Sapphire~1 天前
odoo-049 Pycharm 中 git stash 后有pyc 文件,如何删除pyc文件
ide·git·pycharm