git仓库搭建

第一步安装git

[root@Centos-node2 ~]# yum -y install git

第二步创建git用户

[root@Centos-node2 ~]# useradd git
[root@Centos-node2 ~]# passwd git

第三步创建一个git仓库,例如/data/git.git 路径仓库名称可定义

[root@Centos-node2 ~]# mkdir /data/
[root@Centos-node2 ~]# cd /data/
[root@Centos-node2 data]# git init --bare git.git
初始化空的 Git 版本库于 /data/git.git/
[root@Centos-node2 data]# cd git.git/
#目录结构
[root@Centos-node2 git.git]# tree 
.
├── branches
├── config
├── description
├── HEAD
├── hooks
│   ├── applypatch-msg.sample
│   ├── commit-msg.sample
│   ├── post-update.sample
│   ├── pre-applypatch.sample
│   ├── pre-commit.sample
│   ├── prepare-commit-msg.sample
│   ├── pre-push.sample
│   ├── pre-rebase.sample
│   └── update.sample
├── info
│   └── exclude
├── objects
│   ├── info
│   └── pack
└── refs
    ├── heads
    └── tags

第五步修改权限

[root@Centos-node2 git.git]# chown -R git. /data/git.git/
[root@Centos-node2 git.git]# ll
总用量 12
drwxr-xr-x 2 git git   6 8月  21 21:26 branches
-rw-r--r-- 1 git git  66 8月  21 21:26 config
-rw-r--r-- 1 git git  73 8月  21 21:26 description
-rw-r--r-- 1 git git  23 8月  21 21:26 HEAD
drwxr-xr-x 2 git git 242 8月  21 21:26 hooks
drwxr-xr-x 2 git git  21 8月  21 21:26 info
drwxr-xr-x 4 git git  30 8月  21 21:26 objects
drwxr-xr-x 4 git git  31 8月  21 21:26 refs

第六步克隆(最好找两台机器克隆测试或者不同目录分别克隆也可以)

[root@Centos-node2 tools]# git clone git@192.168.10.138:/data/git.git
正克隆到 'git'...
git@192.168.10.138's password: 
warning: 您似乎克隆了一个空版本库。
[root@Centos-node2 tools]# cd git/
[root@Centos-node2 git]# tree 
.

0 directories, 0 files

第六步测试

#设置一些git全局声明
[root@Centos-node3 git]# git config --global user.email "socloud@sina.com"
[root@Centos-node3 git]# git config --global user.name "Yan shicheng"
[root@Centos-node3 git]#  git config --global push.default simple
#创建文件并且提交git仓库
[root@Centos-node2 git]# for i in `seq 1 100`;do touch yan$i;done
[root@Centos-node2 git]# git add .
[root@Centos-node2 git]# git commit -m "add file"
[root@Centos-node2 git]# git push
git@192.168.10.138's password: 
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 434 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.10.138:/data/git.git
 * [new branch]      master -> master

七 免秘钥设置

    可以把所有人员自己的公钥文件也就是id_rsa.pub文件,导入到git服务器中/home/git/.ssh/authorized_keys文件里

    小团队这个方法就可以了

   也可以通过命令

[root@Centos-node3 ~]# ssh-copy-id -i .ssh/id_rsa.pub git@192.168.10.138

  

posted @ 2018-08-21 21:48  闫世成  阅读(577)  评论(0编辑  收藏  举报