僕は発展途上技術者

続 せっかちな人のための git 入門 - 共有リポジトリの作り方

久々 git のセットアップをすることになり、自分で書いた記事を参考にする。


» せっかちな人のための git 入門 - git をインストールし、共同で開発できる環境を整えるまで : 僕は発展途上技術者


いつのまにかはてなスターがたくさんつき、ブックマーク数も400を超えていた。さすがはてなユーザー。「git なにそれ?」というのが一般ユーザーはもちろん、多くのプログラマー(ブログ書いたり読んだり twitter 使ってたりすると僕らweb系、オープン系が多数派だと勘違いしてしまいそうになるが、決してそうではないのですよね)の反応だと思うのだが。。。


さて、上記記事では触れていない、共有レポジトリの作成方法を書き留めておきます。


まず準備としてリポジトリを使うことになる複数ユーザーを同一グループに所属させます。


太郎くん、次郎くんのアカウントを作成。



% sudo useradd taro

% sudo passwd taro

% sudo useradd jiro

% sudo passwd jiro


group hoge を作成し、taro jiro を hoge に含めます。



% groupadd hoge

% sudo vigr


hoge のユーザーリストに taro jiro を追加します



共有リポジトリを作成します。



% sudo mkdir hoge.git

% cd hoge.git

% sudo git init --bare --shared


git init に --shared オプションをつけ、値を何も指定しない場合、default の --shared=group が適用されます。



The option can have the following values, defaulting to group if no value is given:


» git-init(1)


また、



group (or true): Make the repository group-writable, (and g sx, since the git group may be not the primary group of all users). This is used to loosen the permissions of an otherwise safe umask(2) value. Note that the umask still applies to the other permission bits (e.g. if umask is 0022, using group will not remove read privileges from other (non-group) users). See 0xxx for how to exactly specify the repository permissions.


group (or true) とあるので、sudo git init --bare --shared=group でも sudo git init --bare --shared=true と指定しても結果は同じです。


hoge.git/config ファイルをみてみると、いずれの場合でも、



sharedrepository = 1


となっています。


上記 git の公式ドキュメントにあるように、hoge.git ディレクトリ含め、それ以下のすべてのファイル、ディレクトリのグループ属性に s ビットが立つようになります。


hoge.git 以下すべてのファイルのグループを hoge に変更すれば、hoge グループに属しているユーザーがこのリポジトリに対して読み書きできるようになります。



% cd ..

% chgrp -R hoge hoge.git

% ls -l

drwxrwsr-x 7 root hoge 4096 6月 18 00:42 hoge.git


taro さんがまずローカルマシンで適当にファイルを作成し、レポジトリに push します。



taro% mkdir hoge

taro% cd hoge

taro% git init

taro% git remote add origin ssh://taro@hogehoge.com/var/git/hoge.git

taro% touch README

taro% git add .

taro% git commit -m "Initial import"

taro% git push origin master


次に jiro さんの番です。



jiro% git clone ssh://jiro@hogehoge.com/var/git/hoge.git

jiro% vi README (適当に編集)

jiro% git add .

jiro% git commit -m "Test commit"

jiro% git push origin master


これでちゃんと permission エラーなどにならず、push できれば OK。


最後に taro さんが jiro さんの変更した部分を取り込みます。



taro% git pull origin master


誤りなどありましたらご指摘ください。


参考:

» [git] 共有リポジトリを作る:git init --bare --shared=true - satoko's blog - s21g

» git-init(1)

» gitcvs-migration(7)


プロフィール

株式会社まちクエスト代表、つくる社LLC代表。

Scratchで楽しく学ぶ アート&サイエンスRaspberry Piではじめる どきどきプログラミングを書きました。

オンラインコンテンツ: 大人のためのScratch

Amazonから図書館検索 Libron、iPhoneアプリ ひらがなゲーム かなぶん を作っています。

Email: webmaster at champierre dot com

Twitter @jishiha

最近のエントリー

アーカイブ