D.

git で複数のリモートリポジトリに一度に push したりする。

git リポジトリの .git/config には remote origin となる URL がテキストで書かれている。

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = ssh://user@host/~user/git-bare/repo.git
[branch "master"]
        remote = origin
        merge = refs/heads/master

なお、これらの値は git config -l で参照することもできる。このうち remote.origin.url を書き換えることで pull/push の対象となるリポジトリを指定することができる。

git で複数のリポジトリに同時に push する。

複数のリモートリポジトリに一度に push したい場合は remote.origin.url を 2 行にすれば良い。

[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = ssh://user@hostA/~user/git-bare/repo.git
        url = ssh://user@hostB/~user/git-bare/repo.git

中継点となる git リポジトリを用意する。

インターネット上のホスト A に公開用の bare リポジトリがある。イントラネット上のホスト B は外部と通信できるが、それ以外のホスト C,D,E は通信できない。このような場合に remote origin を以下のようにすることでホスト B を中継して git pull することができる。

ホスト B

        url = ssh://user@hostA/~user/git-bare/repo.git
        url = ~/git-bare/repo.git

ホスト C,D,E

        url = ssh://user@hostB/~user/git-bare/repo.git

ホスト B はリモートリポジトリ及び自身の公開用 bare リポジトリに対して一度に push すれば良い。

ローカルにある公開用リポジトリから pull する。

前回の記事github から移行した場合 remote.origin.url が github のままになっている。これはローカルの git-bare を参照するようにすれば良い。

<   url = git@github.com:yourname/repo.git
---
>   url = ~/git-bare/repo.git

このように url をサーバーのディレクトリ宛に書き換えれば自身の bare リポジトリから pull できる。