$ git clone --bare my_project my_project.git Cloning into bare repository 'my_project.git'... done.
上一章节中咱们远程仓库使用了 Github,Github 公开的项目是免费的,可是若是你不想让其余人看到你的项目就须要收费。git
这时咱们就须要本身搭建一台Git服务器做为私有仓库使用。安全
接下来咱们将以 Centos 为例搭建 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
收集全部须要登陆的用户的公钥,公钥位于id_rsa.pub文件中,把咱们的公钥导入到/home/git/.ssh/authorized_keys文件里,一行一个。app
若是没有该文件建立它:ssh
$ cd /home/git/ $ mkdir .ssh $ chmod 755 .ssh $ touch .ssh/authorized_keys $ chmod 644 .ssh/authorized_keys
首先咱们选定一个目录做为Git仓库,假定是/home/gitrepo/runoob.git,在/home/gitrepo目录下输入命令:curl
$ 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
$ git clone git@192.168.45.4:/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。url
这样咱们的 Git 服务器安装就完成。spa
如今咱们将讨论如何在你本身的服务器上搭建 Git 服务来运行这些协议。
Note
|
这里咱们将要演示在 Linux 服务器上进行一次基本且简化的安装所需的命令与步骤,固然在 Mac 或 Windows 服务器上一样能够运行这些服务。 事实上,在你的计算机基础架构中创建一个生产环境服务器,将不可避免的使用到不一样的安全措施与操做系统工具。可是,但愿你能从本节中得到一些必要的知识。 |
在开始架设 Git 服务器前,须要把现有仓库导出为裸仓库——即一个不包含当前工做目录的仓库。 这一般是很简单的。 为了经过克隆你的仓库来建立一个新的裸仓库,你须要在克隆命令后加上 `--bare`选项 按照惯例,裸仓库目录名以 .git 结尾,就像这样:
$ git clone --bare my_project my_project.git Cloning into bare repository 'my_project.git'... done.
如今,你的 my_project.git
目录中应该有 Git 目录的副本了。
总体上效果大体至关于
$ cp -Rf my_project/.git my_project.git
虽然在配置文件中有若干不一样,可是对于你的目的来讲,这两种方式都是同样的。 它只取出 Git 仓库自身,不要工做目录,而后特别为它单首创建一个目录。
$ cd /opt/git $ mkdir project.git $ cd project.git $ git init --bare Initialized empty Git repository in /opt/git/project.git/