小白教程
所有教程
关于
Search
172.70.126.179
172.70.126.179
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Git 服务器搭建”的源代码
本页内容
上一节:
Git_远程仓库(Github)
下一节:
Git_SourceTree_可视化管理工具
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:Git 服务器搭建}}[[Category:Git 教程|12]] = Git 服务器搭建 = 上一章节中我们远程仓库使用了 Github,Github 公开的项目是免费的,2019 年开始 Github 私有存储库也可以无限制使用。 这当然我们也可以自己搭建一台 Git 服务器作为私有仓库使用。 接下来我们将以 Centos 为例搭建 Git 服务器。 === 1、安装Git === <sample title="" desc="" lang="shell" hererun="1"> $ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel $ yum install git </sample> 接下来我们 创建一个git用户组和用户,用来运行git服务: <sample title="" desc="" lang="shell" hererun="1"> $ groupadd git $ useradd git -g git </sample> === 2、创建证书登录 === 收集所有需要登录的用户的公钥,公钥位于id_rsa.pub文件中,把我们的公钥导入到/home/git/.ssh/authorized_keys文件里,一行一个。 如果没有该文件创建它: <sample title="" desc="" lang="shell" hererun="1"> $ cd /home/git/ $ mkdir .ssh $ chmod 755 .ssh $ touch .ssh/authorized_keys $ chmod 644 .ssh/authorized_keys </sample> === 3、初始化Git仓库 === 首先我们选定一个目录作为Git仓库,假定是/home/gitrepo/xiaobai.git,在/home/gitrepo目录下输入命令: <sample title="" desc="" lang="shell" hererun="1"> $ cd /home $ mkdir gitrepo $ chown git:git gitrepo/ $ cd gitrepo $ git init --bare xiaobai.git Initialized empty Git repository in /home/gitrepo/xiaobai.git/ </sample> 以上命令Git创建一个空仓库,服务器上的Git仓库通常都以.git结尾。然后,把仓库所属用户改为git: <sample title="" desc="" lang="shell" hererun="1"> $ chown -R git:git xiaobai.git </sample> === 4、克隆仓库 === <sample title="" desc="" lang="shell" hererun="1"> $ git clone git@192.168.45.4:/home/gitrepo/xiaobai.git Cloning into 'xiaobai'... warning: You appear to have cloned an empty repository. Checking connectivity... done. </sample> 192.168.45.4 为 Git 所在服务器 ip ,你需要将其修改为你自己的 Git 服务 ip。 这样我们的 Git 服务器安装就完成。
返回至“
Git 服务器搭建
”。
上一节:
Git_远程仓库(Github)
下一节:
Git_SourceTree_可视化管理工具