プロジェクトごとに異なる Git 構成を設定することは可能ですか? 質問する

プロジェクトごとに異なる Git 構成を設定することは可能ですか? 質問する

.gitconfig通常はディレクトリに保存されますuser.home

私は会社 A のプロジェクトでは別の ID を使用し、会社 B では別の ID (主に名前/メール) を使用しています。チェックインが名前/メールと連動しないように、2 つの異なる Git 構成を設定するにはどうすればよいですか?

ベストアンサー1

gitバージョン2.13以降では、gitは条件付き構成には以下が含まれますこの例では、Company A のリポジトリを~/company_aディレクトリにクローンし、Company B のリポジトリを にクローンします~/company_b

ファイルの最後に.gitconfig、次のような内容を追加できます。

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

内容の例.gitconfig-company_a([core]グローバル SSH キーを使用できる場合は、このセクションを省略できます):

[user]
name = John Smith
email = [email protected]

[core]
sshCommand = ssh -i ~/.ssh/id_rsa_companya

内容の例.gitconfig-company_b:

[user]
name = John Smith
email = [email protected]

[core]
sshCommand = ssh -i ~/.ssh/id_rsa_companyb

おすすめ記事