Is it possible to have different Git configuration for different projects?

前端 未结 12 780
萌比男神i
萌比男神i 2020-12-02 03:44

.gitconfig is usually stored in the user.home directory.

I use a different identity to work on projects for Company A and something else fo

12条回答
  •  没有蜡笔的小新
    2020-12-02 03:54

    As of git version 2.13, git supports conditional configuration includes. In this example we clone Company A's repos in ~/company_a directory, and Company B's repos in ~/company_b.

    In your .gitconfig you can put something like this.

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

    Example contents of .gitconfig-company_a

    [user]
    name = John Smith
    email = john.smith@companya.net
    

    Example contents of .gitconfig-company_b

    [user]
    name = John Smith
    email = js@companyb.com
    

提交回复
热议问题