[git]+[gitosis]+[gitweb]on[Cent OS][Ubuntu]

[git]+[gitosis]+[gitweb]on[Cent OS][Ubuntu]


  1. 新たなプロジェクトが立ち上がった際、プロジェクトメンバーは自分の公開鍵をgitosis管理者へ送付する。
  2. gitosis管理者はプロジェクト用のgit公開リポジトリをサーバ上に作成。必要であればgitosisの設定を変更する。(グループの追加、メンバーの追加/削除など)(後述)
  3. メンバーは新に作成された公開リポジトリからclone(checkout)、編集(ローカルへcommit)、push(サーバ上のリポジトリに反映)する。

Install of git
以下、gitosis管理者(repomasterで公開レポジトリを作成するサーバ上で実行) Ubuntuの場合はyumをaptitudeにchangeなうする。

  • sudo rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
  • sudo yum install git
  • git config –global user.name “repomaster”
  • git config –global user.email “repomaster@example.com”

Install of gitosis

  • sudo yum install gitosis
  • su -
  • adduser –shell /bin/sh -c ‘git version control’ –home-dir /home/git git
  • exit
  • (ubuntuだとsu -なしで)
  • sudo adduser –system –shell /bin/sh –gecos ‘git version control’ –group –disabled-password –home /home/git git
  • ssh-keygen -t rsa
  • sudo -H -u git gitosis-init < /home/repomaster/.ssh/id_rsa.pub
  • sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update
  • git clone git@localhost:gitosis-admin.git

Add project and members


[group gitosis-admin]
writable = gitosis-admin
members = repomaster@example.com

[group team-noob]
writable = noobreproject
members = repomaster@example.com newbie

writable(プロジェクト)とmembers(コミッター)はスペース区切りで複数指定できる。writable → readonlyに変えるとそのグループのメンバーはpushできなくなる。
newbie(コミッター)から公開鍵をもらったら、/home/repomaster/gitosis-admin/keydir/newbie.pub に保存
( 公開鍵のファイル名は #{membersに追加した名前}.pub )

  • git commit -a -m ‘Add new project and member for noob project.’
  • git push


  • mkdir noobproject
  • cd noobproject
  • touch README
  • git init
  • git add .
  • git commit -m ‘first commit.’
  • git remote add origin git@#{SERVERNAME}:noobreproject.git
  • git push origin master

Install of gitweb(Ubuntu)

  • sudo yum install gitweb
  • sudo vim /etc/gitweb.conf
# path to git projects (.git)
$projectroot = "/home/git/repositories";

# directory to use for temp files
$git_temp = "/tmp";

# target of the home link on top of all pages
#$home_link = $my_uri || "/";

# html text to include at home page
$home_text = "indextext.html";

# file with project list; by default, 
# simply scan the projectroot dir.
#$projects_list = $projectroot;
$projects_list = "/home/git/gitosis/projects.list";

$export_ok = "";
$strict_export = "true";

# stylesheet to use
$stylesheet = "/gitweb/gitweb.css";

# logo to use
$logo = "/gitweb/git-logo.png";

# the 'favicon'
$favicon = "/gitweb/git-favicon.png";
  • sudo vim /etc/apache2/sites-available/gitweb

    Options ExecCGI
    AddHandler cgi-script .cgi
    AllowOverride None
    DirectoryIndex gitweb.cgi
    Order allow,deny
    allow from all

  • sudo ln -s /etc/apache2/sites-available/gitweb /etc/apache2/sites-enabled/001-gitweb
  • sudo service apache2 restart

Install of gitweb(Cent OS) (試してないけど)

  • su -
  • yum install gitweb
  • cp /var/www/git/* /var/lib/gitosis/
  • vim /etc/httpd/conf.d/vhosts.conf

    ServerAdmin user-name@your-domain.com
    ServerName git.your-domain.com

    SetEnv  GITWEB_CONFIG   /var/lib/gitosis/gitosis/gitweb.conf

    Alias /gitweb.css /var/lib/gitosis/gitweb.css
    Alias /git-logo.png /var/lib/gitosis/git-logo.png
    Alias /git-favicon.png /var/lib/gitosis/git-favicon.png

    ScriptAlias /cgi-bin /var/lib/gitosis

    DocumentRoot /home/git/repositories
        Options Indexes FollowSymlinks ExecCGI
        AllowOverride None
        Order allow,deny
        Allow from all

        DirectoryIndex /cgi-bin/gitweb.cgi

        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^.* /cgi-bin/gitweb.cgi/$0 [L,PT]

    LogLevel debug
    ErrorLog logs/git.your-domain.com-error_log
    CustomLog logs/git.your-domain.com-access_log common

  • htpasswd -c /var/lib/gitosis/.htpasswd root
  • cp /usr/share/doc/gitosis-0.2/gitweb.conf /var/lib/gitosis/gitosis/
  • vim /var/lib/gitosis/.htaccess
AuthUserFile /var/lib/gitosis/.htpasswd
AuthGroupFile /dev/null
AuthName "Please enter your ID and password"
AuthType Basic
require valid-user


# Include the global configuration, if found.
do "/etc/gitweb.conf" if -e "/etc/gitweb.conf";

# Point to projects.list file generated by gitosis.
# Here gitosis manages the user "git", who has a
# home directory of /srv/example.com/git
#$projects_list = "/srv/example.com/git/gitosis/projects.list";
$projects_list = "/home/git/gitosis/projects.list";

# Where the actual repositories are located.
#$projectroot = "/srv/example.com/git/repositories";
$projectroot = "/home/git/repositories";

# By default, gitweb will happily let people browse any repository
# they guess the name of. This may or may not be what you wanted.  I
# choose to allow gitweb to show only repositories that git-daemon
# is already sharing anonymously.
$export_ok = "";

# Alternatively, you could set these, to allow exactly the things in
# projects.list, which in this case is the repos with gitweb=yes
# in gitosis.conf. This means you don't need daemon=yes, but you
# can't have repositories hidden but browsable if you know the name.
# And note gitweb already allows downloading the full repository,
# so you might as well serve git-daemon too.
# $export_ok = "";
$strict_export = "true";

# A list of base urls where all the repositories can be cloned from.
# Easier than having per-repository cloneurl files.
#@git_base_url_list = ('git://example.com');
@git_base_url_list = ('git://your-domain.com');

$feature{'search'}{'default'} = [1];
$feature{'blame'}{'default'} = [1];
$feature{'pickaxe'}{'default'} = [1];
$feature{'grep'}{'default'} = [1];
$feature{'snapshot'}{'default'} = [1];

Change gitosis’ config for gitweb

gitweb = yes

[group gitosis-admin]
writable = gitosis-admin
members = repomaster@example.com

[group team-noob]
writable = noobreproject
members = repomaster@example.com newbie

[repo noobreproject]
description = project for newbie.
owner = repomaster@example.com
gitweb = yes
  • git commit -a -m ‘Add config for gitweb.’
  • git push

Access to http://#{SERVERNAME}/cgi-bin/gitweb.cgi

  • git branch -a
  • git checkout -b localBranchName origin/branchName

Facebook comments:

7 thoughts on “[git]+[gitosis]+[gitweb]on[Cent OS][Ubuntu]

  1. Its like you read my mind! You appear to know so much about this,
    like you wrote the book in it or something. I think that
    you could do with some pics to drive the message home a bit, but other than that,
    this is fantastic blog. A great read. I will definitely be back.


メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>