2015年8月18日 星期二

[Git] 使用HTTP存取Git Server on Ubuntu 14.04


  • 安裝 Git和apache2
  • #apt-get install git-core apache2 apache2-utils

  • 啟動DAV模組
  • #a2enmod dav_fs
    #a2enmod dav

  • 新增git.conf
  • #vim /etc/apache2/sites-available/git.conf
    <VirtualHost 192.168.1.50>
            DocumentRoot /home/git
            ErrorLog /var/log/apache2/git-error.log
            CustomLog /var/log/apache2/git-access.log combined

            <Location "/test.git">
                    DAV on
                    AuthType Basic
                    AuthName "Git Access"
                    AuthUserFile /etc/apache2/dav_git.passwd
                    Require valid-user
            </Location>
    </VirtualHost>

  • 建立帳號密碼
  • #htpasswd -c /etc/apache2/dav_git.passwd USERNAME

  • enable git.conf
  • #ln -s /etc/apache2/sites-available/git.conf /etc/apache2/sites-enabled/git.conf

  • 重新啟動Server
  • #/etc/init.d/apache2 restart

  • 建立Repository
  • #mkdir /home/git/test.git
    #cd /home/git/test.git
    #git init --bare
    #git update-server-info
    #cp hooks/post-update.sample hooks/post-update
    #chown www-data:www-data /home/git/test.git -R

  • 測試git repository
  • #git clone http://192.168.1.50/test.git
    #cd test
    #touch README
    #git add README
    #git commit -m "init"
    #git push

  • 如果發生Push Error,則可使用10解決
  • error: Cannot access URL http://192.168.1.50/test.git/, return code 22
    fatal: git-http-push failed
    error: failed to push some refs to 'http://192.168.1.50/test.git'

  • 解決Push Error
  • 發生錯誤的原因為未認證,可修正clinet端的config解決該問題。
    #vim test/.git/config
    Modify
    [remote "origin"]
            url = http://192.168.1.50/test.git

    to
    [remote "origin"]
            url = http://jesse@192.168.1.50/test.git


Reference:
[1] Debian Linux 架設使用 HTTP 存取 的 Git Server

沒有留言:

張貼留言