Linux-Git仓库搭建

Linux-Git仓库搭建

说明

在之前的Linux-Git详细描述文章中,给大家介绍了Git的相关知识的,本文给大家介绍了如何创建Git仓库。

详细步骤

1.下载git

当前用户为root
命令: apt-get install git
说明:  我这是ubuntu系统,直接用apt-get install git,centos 的用yum install git

2.创建git用户用来管理仓库 也可以是其他用户

命令: adduser git 
说明: 添加git用户用来管理仓库,添加上密码之后一路回车就好,adduser命令会自动创建git家目录 /home/git

3.切换git用户 进到根目录

密令:su git
说明:su命令切换到git用户下,用ssh-keygen用来生成ssh公钥认证所需的公钥和私钥文件,

4.生成公钥文件

命令:ssh-keygen
说明:用来生成ssh公钥认证所需的公钥和私钥文件 也可以用 ssh-keygen -t rsa -P ''
-P表示密码,-P '' 就表示空密码,也可以不用-P参数,这样就要三车回车,用-P就一次回车。
说明:  ssh-keygen 
执行结果:
git@iZm5eiw4hobozjn054cjzrZ:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/git/.ssh/id_rsa):
Created directory '/home/git/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/git/.ssh/id_rsa.
Your public key has been saved in /home/git/.ssh/id_rsa.pub.
The key fingerprint is:
d0:87:0f:a4:58:bb:69:33:4d:fb:09:e9:7a:80:5a:b5 git@iZm5eiw4hobozjn054cjzrZ
The key's randomart image is:
+--[ RSA 2048]----+
|      . .        |
|     o = .       |
|    . + = .      |
|      .* *       |
|     o*.S .      |
|    o.E+ o .     |
|   o   .. o      |
|  .    ..        |
|      ..         |
+-----------------+

创建成功后当前目录下会有一个隐藏文件夹 .ssh,里边就是公钥和私钥文件
git@iZm5eiw4hobozjn054cjzrZ:~/.ssh$ ls
id_rsa  id_rsa.pub

5.创建authorized_keys 文件

vim authorized_keys
authorized_keys 文件是用来存储免密码登录的用户公钥的,讲用户的公钥放到这个文件下,用户就可以免密码登录克隆
本文就先创建一个空文件就好,楼主第二篇文章中会给大家介绍怎么使用

6.创建仓库目录

mkdir depot
cd ./depot

7. 创建init.php (当前目录下编写脚本文件,自动生成仓库的文件,可以直接拿来用)

<?php
if(count($argv) == 1){echo "php init.php 仓库名称  ios,www,android\n";exit;}

$tPlatform = array('ios','www','android');
if(isset($argv[2])){$tPlatform = explode(',',$argv[2]);}

$tDir =  __DIR__;

foreach($tPlatform as $tPF){
        $tRepository = $tDir.'/'.$argv[1].'_'.$tPF.'.git';
        if(is_dir($tRepository)){echo $tRepository.'已存在';continue;}
        exec('git init --bare ' . $tRepository);
        exec('chown -R git:git ' . $tRepository);
        echo $tRepository.'创建成功';
        echo "\r\n";
}
init.php 使用方法  php init.php [仓库名] [项目类型]
项目类型为ios,www,android,分别对应 ios项目、网站项目、安卓项目 

8.执行文件创建仓库

命令:php init.php test www
执行结果:
git@iZm5eiw4hobozjn054cjzrZ:~/depot$ php init.php test www
/home/git/depot/test_www.git创建成功

结尾

我只愿面朝大海,春暖花开--《面朝大海,春暖花开》

添加新评论