kikukawa's diary

都内で活動するシステムエンジニアが書いてます。 興味を持った技術やハマったポイント、自分用メモをつけてます。 最近はweb中心

特定のディレクトの配下でgitのconfigを切り替える

リポジトリの状況

~/workspace
  |-- foo
  |   `-- foo-repo
  `-- bar
      |-- bar-repo1
      `-- bar-repo2

~/workspce に切り替えたい単位にディレクトリを作成しそれぞれリポジトリを置いてます。

ホーム配下

~/
  .gitconfig -> dotfiles/.gitconfig
  .gitconfig.local
  .gitconfig.foo
  .gitconfig.bar
  dotfiles
    `-- gitconfig

dotfiles(github管理)のしたに .gitconfig を作成しどこでも使うものはそこに記述します。 それをシンボリックリンクで、HOME配下に配置します。 PCごとに違う設定にしたいものは .gitconfig.local に。 .gitconfig.localincludeIf を使って案件ごとの設定を記述します。

.gitconfig

[include]
  path = .gitconfig.local

.gitconfig.local

[includeIf "gitdir:~/workspace/foo/"]
  path = .gitconfig.foo
[includeIf "gitdir:~/workspace/bar/"]
  path = .gitconfig.bar

.gitconfig.foo, .gitconfig.bar

[user]
    name=example
    email=example@example.com