centos簡單搭建git服務端

注意事項:

1、Git常用的客戶端管理工具有sourcetree、TortoiseGit,個人比較喜歡sourcetree

2、按照本文裝的git服務端如果需要創建用戶得在命令行操作,也可部署gitlab開源項目實現在web端進行管理用戶

3、如果覺得麻煩不想自己部署,也可直接把代碼推廣到github上


本人採用的是virtualbox虛擬機,服務端系統centos6.6版本安裝git1.7.1版本,客戶端採用的是Git-2.7.2+sourceTree1.4.0

客戶端

1、客戶端創建ssh key

進入sourceTree終端,輸入$ ssh-keygen -t rsa -C "[email protected]"  #後面爲郵箱地址

2、上傳公鑰

打開C盤/用戶/.ssh目錄會有一個id_rsa.pub文件,上傳至服務器tmp文件夾,以便備用


服務端

1、安裝git

[root@localhost ~]# yum install -y git

2、創建git用戶

[root@localhost ~]# adduser git

3、初始化git倉庫

[root@localhost ~]# cd /data/git/

[root@localhost git]# git init --bare /data/git/learngit.git  #--bare初始化裸倉庫,不會包含實際項目源文件

Initialized empty Git repository in /data/git/learngit.git/ 

4、更改倉庫擁有者

[root@localhost git]# chown git:git learngit.git

5、將公鑰拷貝到authorized_keys權限文件

[root@localhost git]# cd /home/git

[root@localhost git]# ll -a #查看當前文件夾中的文件,是否有.ssh目錄,如果沒有則創建.ssh/authorized_keys

[root@localhost git]# cat /tmp/id_rsa.pub >> /home/git/.ssh/authorized_keys #將上傳的id_rsa.pub的公鑰寫入到權限文件


測試

1、打開sourceTree點擊“克隆/新建”

2、輸入git clone [email protected]:/data/git/learngit.git,出現下圖所視表示成功

大功告成


另外:

如果是項目需要邊測試邊上線使用,可以在服務端克隆出來兩個目錄main(項目真是運營目錄)和mainCode(僅供測試使用)

[root@localhost ~]# cd main

[root@localhost ~]# git clone [email protected]:/data/git/learngit.git

測試好了,再把mainCode裏面的源碼部署到main目錄下。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章