git コマンドの -c オプション

2024/04/28に公開

git コマンドの -c オプション

git config コマンドで各種設定を行うことができる。
git config コマンドでは設定ファイルに設定が保存されるため、一時的に反映したい設定の場合に使いにくい。

-c で指定することで 設定ファイルに設定を保存せずに git config で設定したのと同様の設定を行うことができる。

git -c <設定項目>=<設定値> コマンド ...

具体例 (insteadOf)

insteadOf の設定に関して

git config --global url."A".insteadOf B

C 言語の typedef A B; と順番は同じ

  • A は実際の型
  • B は定義を利用する利用者が意識するURL

A

実際に git がアクセスする URL または URLの一部を指定する。

B

ユーザーが git に渡すURL あるいはURL の一部を指定する

git config を使う場合

git config --global url."https://github.com/yoctoproject/poky.git".insteadOf https://git.yoctoproject.org/git/poky
git clone https://git.yoctoproject.org/git/poky

git config --global url."https://github.com/yoctoproject/poky.git".insteadOf "https://git.yoctoproject.org/git/poky"

この場合 ユーザーが https://git.yoctoproject.org/git/poky にアクセスすると実際には
git は https://github.com/yoctoproject/poky.git にアクセスする。

-c を使う場合

git -c \
url."https://github.com/yoctoproject/poky.git".insteadOf="https://git.yoctoproject.org/git/poky" \
clone https://git.yoctoproject.org/git/poky

参考サイト

Discussion