假设你已经在本地搭建了一个 git repository,现在需要把它上传到 dreamhost 主机上提供给别人 pull,并方便自己在不同电脑上更新使用。这是我目前用的方法,当然首先你得先知道以下东西 ( 以下内容均为假设,表胡猜我的帐号,密码了:D)

  • DH 主机名: montty ( 假设 )
  • DH 用户名: hades ( 需开通 shell 操作权限 )
  • 本地 Git repo: /home/hades/software

1.在 DH 主机上安装 Git

ssh 登陆 DH 主机,在主目录下进行以下操作安装 Git

$ mkdir src && cd src/
$ wget http://kernel.org/pub/software/scm/git/git-1.5.4.4.tar.gz
$ tar xzvf git-1.5.4.4.tar.gz
$ cd git-1.5.4.4
$ ./configure --prefix=/home/hades/ NO_CURL=1 NO_MMAP=1
$ make && make install

然后把生成的/home/hades/bin 添加到系统环境中

$ echo "export PATH=/home/hades/bin:$PATH" >> ~/.bashrc

2.从本地拷贝一个空 (bare) 的 repo 出来

$ cd /home/hades
$ git-clone --bare software software.git
$ cd software.git/
$ git --bare update-server-info
$ chmod a+x hooks/post-update
$ touch git-daemon-export-ok

3.把这个 software.git 上传到 DH 主机上

$ scp -r software.git hades@montty.dreamhost.com:/example.com/path/software.git

4.回到本地的原始 Git repo 目录,提交改变到 DH 主机的 repo 上

$ git-push ssh://hades@montty.dreamhost.com/home/hades/example.com/path/software.git

如果你嫌反复输入这么长的操作命令的话

$ git remote add git-software \
  ssh://hades@montty.dreamhost.com/home/hades/example.com/path/software.git

以后你只需要输入 git-push git-software 就行了

5.查看 DH 主机的 repo

$ git-clone http://example.com/path/software.git

确认下 DH 主机上的 repo 是否已成功导入本地 repo 的内容及更新。

参考: