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

前端 未结 12 733
萌比男神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 04:11

    Thanks @crea1

    A small variant:

    As it is written on https://git-scm.com/docs/git-config#_includes:

    If the pattern ends with /, ** will be automatically added. For example, the pattern foo/ becomes foo/**. In other words, it matches foo and everything inside, recursively.

    So I use in my case,
    ~/.gitconfig :

    [user] # as default, personal needs
        email = myalias@personal-domain.fr
        name = bcag2
    [includeIf "gitdir:~/workspace/"] # job needs, like workspace/* so all included projects
        path = .gitconfig-job
    
    # all others section: core, alias, log…
    

    So If the project directory is in my ~/wokspace/, default user settings is replace with
    ~/.gitconfig-job :

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

提交回复
热议问题