すたらブログ

文系Webプログラマの備忘録

Windows: LAN内専用のGitリモートリポジトリを作る

(最終更新: 2015-12-04)

目次


要望

グループ開発のためにLAN内だけのGitリポジトリがほしい。
外部には公開しない。


結論

必要なコマンドだけをまとめます。
詳しくは以降の章で説明します。

環境例

  • Gitサーバーを置く機器名: XPS8700
  • Gitサーバー名: sample.git
  • ネットワークパス: \\XPS8700\sample.git
  • リモート名: origin

コマンド

Gitサーバー作成

$ mkdir sample.git
$ cd sample.git
$ git init --bare --shared=true
$ touch git-daemon-export-ok

既存リポジトリから継続する場合

$ git remote add origin //XPS8700/sample.git
$ git push origin master

各メンバーがクローンして準備完了

$ git clone //XPS8700/sample.git

Gitサーバーを作る

まず、任意の場所にフォルダを作って共有します。
名前はxxxx.gitとするのが流儀だそうです。

  • ローカルパス: C:\Users\Yuusaku\Documents\sample.git
  • ネットワークパス: \\XPS8700\sample.git
    またはIPアドレスで表記する。 \\192.168.1.100\sample.git

次に、Gitサーバーとして初期化します。
git-daemon-export-okも作成して、認証を省いて使いやすくします。
LAN内専用なのでこれでかまいません。

$ git init --bare --shared=true
$ touch git-daemon-export-ok

–bare
Create a bare repository. If GIT_DIR environment is not set, it is set to the current working directory.

–shared[=(false|true|umask|group|all|world|everybody|0xxx)]
Specify that the Git repository is to be shared amongst several users. This allows users belonging to the same group to push into that repository. When specified, the config variable “core.sharedRepository” is set so that files and directories under $GIT_DIR are created with the requested permissions. When not specified, Git will use permissions reported by umask(2).

(git-daemon-export-ok について)
このファイルが存在するプロジェクトについては、Git は認証なしで公開してもよいものとみなします。


Gitサーバーを起動する

下記のコマンドでGitサーバーを起動します。
ただ、私の環境では何故か下記のコマンドを実行しなくても、pushやpull、cloneが可能です。

$ git daemon --export-all --enable=receive-pack

–export-all
Allow pulling from all directories that look like Git repositories (have the objects and refs subdirectories), even if they do not have the git-daemon-export-ok file.

–enable=<service>
–disable=<service>
Enable/disable the service site-wide per default. Note that a service disabled site-wide can still be enabled per repository if it is marked overridable and the repository enables the service with a configuration item.

SERVICES
receive-pack
This serves git send-pack clients, allowing anonymous push. It is disabled by default, as there is no authentication in the protocol (in other words, anybody can push anything into the repository, including removal of refs). This is solely meant for a closed LAN setting where everybody is friendly. This service can be enabled by setting daemon.receivepack configuration item to true.


グループ開発を始める

クローン

開発メンバーがそれぞれのリポジトリにcloneします。

$ git clone //XPS8700/sample.git
$ git clone //192.168.1.100/sample.git # IPアドレスでも指定できる

パスはgit://, file://, ssh://, https://などではなく、UNCで指定します。
これになかなか気づかなかった…orz

既に開発中で、後からGitを利用したくなった場合

代表者が既存のリポジトリにリモートを追加し、pushします。

$ git remote add origin //XPS8700/sample.git
$ git push origin master

その後、上のように各メンバーがcloneします。