gitでリモートリポジトリからpullだけ許す
問題:gitでリモートリポジトリ(例えばorigin)からのpullとfetchは許すが、pushはできないように設定する方法は?
答え:.git/configの[remote "origin"]の項目に「pushurl = 」を追加する。
[remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = /home/ksakamot/git/test.git pushurl =
こうすると、pullとfetchではurlで指定したレポジトリをデフォルトで参照する一方、pushでは参照先がなくなります。ただし、レポジトリURLを直接指定すればpushできます。
マニュアルの記述
以下のマニュアル記述を参考にしました。
REMOTES
The name of one of the following can be used instead of a URL as
argument: a remote in the git configuration file: $GIT_DIR/config,
(中略)
All of these also allow you to omit the refspec from the command line because they each contain a refspec which git will use by default.
Named remote in configuration file
You can choose to provide the name of a remote which you had previously configured using git-remote(1), git-config(1) or even by a manual edit to the $GIT_DIR/config file. The URL of this remote will be used to access the repository. The refspec of this remote will be used by default when you do not provide a refspec on the command line. The entry in the config file would appear like this:[remote ""] url = pushurl = push = fetch = The
is used for pushes only. It is optional and defaults to .