建立自己的git服务器

需求情景

就像金山快盘同步盘那样, 在开发环境windows 10和部署环境Ubuntu server 14.04之间建立同步关系.比如windows端多了一个a.txt文件,你推送后,Ubuntu端也就会增加一个同样的a.txt文件.注意,现在网络上许多关于git远程仓库的教程其实都不是把文件原原本本地推送到服务器上的.它们只是建立一个裸仓库,这个仓库能供其他主机clone.

假设

比如我是想在win端c:\projects\abc和Ubuntu端/root/projects/abc建立同步关系,服务器的域名是example.com.

分别在windows和Ubuntu安装git

git的版本需要不小于2.3

windows安装git

windows比较简单,点击这里进行

Ubuntu安装git

这个可能要麻烦一些,比如阿里云服务器,你用apt-get install git的方式安装只能得到1.9的版本.如果是这种情况,就需要手动从源码安装.
查看安装方法

配置git

安装成功后,两端都需要配置一下基本信息.
git config --global user.email "you@example.com"
git config --global user.name "Your Name"

配置ssh key

windows端在git bash界面进行(这个安装了git之后自然就会有).之后请参照这个教程进行.

建立仓库

win端

cd "c:\projects\abc"
git init && git add -A && git commit -m "first commit"
git remote add origin root@example.com:/root/projects/abc/.git/

ubuntu端

cd /root/projects/abc
git init
git config receive.denyCurrentBranch updateInstead

回到win端

git push -u origin --all

搞定.

posted @ 2016-02-27 13:59  LisPythoniC  阅读(223)  评论(0编辑  收藏  举报