この内容は古いバージョンです。最新バージョンを表示するには、戻るボタンを押してください。
バージョン:7
ページ更新者:T
更新日時:2026-06-11 07:10:02

タイトル: 設定の確認
SEOタイトル: git 設定 (config) 確認完全ガイド (global / local / system / includeIf)

この記事の要点
  • 全設定の確認: git config --list または git config -l
  • 3 つのスコープ: --system (全体) → --global (ユーザー) → --local (リポジトリ)。後者ほど優先
  • 個別の値: git config --get user.name
  • 定義元込み: git config --list --show-origin でどのファイルか分かる
  • Conditional Include: includeIf "gitdir:/work/" で仕事用とプライベート用を自動切替

基本: 全設定を一覧

# 全設定を表示
git config --list
git config -l         # 短縮形

# 出力例
# user.email=foo@example.com
# user.name=Foo Bar
# core.editor=vim
# core.autocrlf=input
# pull.rebase=true
# alias.st=status

3 つのスコープ

Git の設定は 3 階層に保存されます。後者ほど優先 (上書き) されます:

スコープファイル適用範囲優先度
--system/etc/gitconfigマシン全ユーザー
--global~/.gitconfig または ~/.config/git/configユーザー全リポジトリ
--local.git/configこのリポジトリのみ高 (最優先)
--worktree.git/config.worktreeworktree 単位最高
# スコープ別に表示
git config --system --list      # システム全体
git config --global --list      # ユーザー設定
git config --local --list       # リポジトリ設定

# 各 .gitconfig を直接見る
cat /etc/gitconfig
cat ~/.gitconfig
cat .git/config

個別の値を取得

# user.name の値
git config --get user.name
git config user.name           # --get は省略可

# core.editor
git config --get core.editor

# 該当キーが無ければデフォルト
git config --get user.name || echo "未設定"

# 複数値 (alias 等) を全部
git config --get-all remote.origin.fetch

# 正規表現で部分一致
git config --get-regexp "^user\."
# user.email foo@example.com
# user.name Foo Bar

git config --get-regexp "alias\."
# alias.st status
# alias.co checkout

定義元 (どのファイルか) を表示

「user.email が会社の値になってしまう」「どこで設定されているか分からない」ときに最も有用なオプション:

git config --list --show-origin

# 出力例
# file:/etc/gitconfig                core.autocrlf=input
# file:/Users/foo/.gitconfig         user.name=Foo Bar
# file:/Users/foo/.gitconfig         user.email=personal@example.com
# file:.git/config                   user.email=work@company.com  ← これが最優先
# file:.git/config                   remote.origin.url=git@github.com:org/repo.git

# スコープも表示
git config --list --show-origin --show-scope

# 個別キーの定義元
git config --show-origin user.email

典型的な確認シナリオ

1. コミット時の名前・メールを確認

git config user.name
git config user.email

# 設定 (リポジトリ単位で仕事用に上書き)
git config --local user.email "work@company.com"

# グローバル (デフォルト)
git config --global user.name "Foo Bar"
git config --global user.email "foo@example.com"

2. push のデフォルト動作

git config push.default
# simple (推奨) / current / matching / upstream

git config pull.rebase
# true (rebase) / false (merge、デフォルト)

git config --global pull.rebase true

3. リモート URL の確認

git config --get remote.origin.url
git remote -v                       # こちらが一般的
git remote get-url origin

4. エイリアスの確認

git config --get-regexp "^alias\."

# 設定
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.lg "log --oneline --graph --all"

Conditional Include (includeIf)

「会社のディレクトリでは仕事用メール、プライベートディレクトリでは個人メール」を 自動切替する仕組み。Git 2.13+ で対応。

# ~/.gitconfig
[user]
    name = Foo Bar
    email = personal@example.com   # デフォルト

[includeIf "gitdir:~/work/"]
    path = ~/.gitconfig-work

[includeIf "gitdir:~/oss/"]
    path = ~/.gitconfig-oss
# ~/.gitconfig-work
[user]
    email = foo@company.com
    signingkey = ABCDEF1234
[commit]
    gpgsign = true

これで ~/work/ 配下のリポジトリでは自動的に仕事用設定が適用されます。git config --list --show-origin で確認可能。

主要設定キーの一覧

キー意味
user.nameコミットの名前Foo Bar
user.emailコミットのメールfoo@example.com
user.signingkeyGPG / SSH 署名鍵ABCDEF1234
core.editorコミットメッセージのエディタvim / code -w
core.autocrlf改行コード変換input (Mac/Linux) / true (Windows)
core.ignorecaseファイル名大文字小文字true (Mac) / false (Linux)
init.defaultBranch初期ブランチ名main
pull.rebasepull の動作true (rebase)
push.defaultpush の動作simple
commit.gpgsign署名コミットtrue
credential.helper認証情報キャッシュosxkeychain / store

設定の追加・変更・削除

# 追加・上書き
git config --global user.name "Foo Bar"

# 削除
git config --global --unset user.name

# 全削除 (スコープ指定)
git config --global --unset-all alias.st

# セクション全部削除
git config --global --remove-section alias

# 編集モード (エディタで開く)
git config --global --edit
git config --local -e

FAQ

Q: コミットすると会社のメールになってしまう
A: git config --list --show-origin user.email で定義元を確認。.git/config (リポジトリ) > ~/.gitconfig (グローバル) の順で上書きされます。個人用リポジトリでは git config --local user.email "personal@example.com"

Q: --global を付け忘れた
A: リポジトリ単位 (--local) に書かれます。確認は git config --local --list。削除は git config --local --unset key

Q: 設定ファイルを直接編集していい?
A: OK。~/.gitconfig.git/config はテキストファイル。ただし構文ミスで Git が動かなくなることがあるので、コマンド経由が無難。

Q: GitHub の SSH 鍵も git config で確認できる?
A: いいえ。SSH 鍵は ~/.ssh/ 配下。cat ~/.ssh/configssh -T git@github.com で確認。