最近由于项目需求,须要实现一个原型系统,加上后期项目须要多人协做,考虑采用了git作版本控制。git
这里主要简要描述下git服务器和客户端的搭建和配置。服务器
一、git服务器ssh
(1)安装git分布式
sudo apt-get install git
git是一个分布式的版本控制工具,每一个git仓库既能够做为服务器也能够做为客户端(不一样于svn采用的集中式版本控制),故安装完成后须要配置用户信息svn
git config --global user.name "mal" git config --global user.email malt@gmial.com
(2)添加git用户,避免项目和其余文件相互冲突工具
adduser git
passwd git
(3)使用git用于新建一个仓库spa
git@malt:~$ mkdir res.git git@malt:~$ cd res.git/ git@malt:~/res.git$ git --bare init
这里建立res.git仓库是使用git用户建立的,若是是root用户建立,后续采用 git remote add origin git@127.0.0.1:/home/git/res.git,对应权限错误。版本控制
二、git客户端code
在git服务器远程仓库创建好后,就能够在客户端将本身的仓库加入到远程仓库中了。blog
whthomas@whthomas:~/workplace/gitu$ git init 初始化空的 Git 版本库于 /home/whthomas/workplace/gitu/.git/ whthomas@whthomas:~/workplace/gitu$ touch README whthomas@whthomas:~/workplace/gitu$ echo hello >> README whthomas@whthomas:~/workplace/gitu$ cat README hello whthomas@whthomas:~/workplace/gitu$ git add . whthomas@whthomas:~/workplace/gitu$ git commit -m "add a README" [master (根提交) 59d4695] add a README 1 file changed, 1 insertion(+) create mode 100644 README whthomas@whthomas:~/workplace/gitu$ git remote add origin git@127.0.0.1:/home/git/res.git whthomas@whthomas:~/workplace/gitu$ git push origin master Counting objects: 3, done. Writing objects: 100% (3/3), 216 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To git@127.0.0.1:/home/git/res.git * [new branch] master -> master
一样的,也能够在其余目录下git clone远程仓库
git clone git@localhost:/home/git/res.git
三、设置免密码push
在git服务器的git用户目录下。新建目录和文件(若是存在则不须要新建)
$ cd /home/git $ mkdir .ssh $ chmod 700 .ssh $ touch .ssh/authorized_keys $ chmod 600 .ssh/authorized_keys
在git客户端中,查看ssh公私钥,若是没有,使用命令"ssh-keygen"能够建立
其中id_rsa.pub为公钥,将其内容复制并追加到git服务器的authorized_keys中。以后则能够免密链接远程仓库。