git config

git

書き方

git config [--global] <key> [<value>]

gitの設定を読み書きします。--globalを付けないと今のリポジトリにしか書かれず、新しくクローンした所には引き継がれません。

よく使うオプション

オプション意味
--globalwrite to ~/.gitconfig for every repository
--localwrite to .git/config, the default
--list --show-originprint every setting and the file it came from
--get <key>print one value
--unset <key>delete one setting
-eopen the config file in your editor

git config --global user.email "me@example.com"

sets the address every future commit is signed with

git config --global init.defaultBranch main

new repositories start on main instead of master

git config --list --show-origin

shows which file each setting comes from

取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. git config は何をしますか。

gitの設定を読み書きします。--globalを付けないと今のリポジトリにしか書かれず、新しくクローンした所には引き継がれません。

Q. どう打ちますか。

git config [--global] <key> [<value>] — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは6個です。全部は man git にあります。このコマンドはgitの仲間です。

関連するコマンド

man ページ: man git-config