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

前端 未结 12 787
萌比男神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:16

    You can customize a project's Git config by changing the repository specific configuration file (i.e. /path/to/repo/.git/config). BTW, git config writes to this file by default:

    cd /path/to/repo
    git config user.name 'John Doe'  # sets user.name locally for the repo
    

    I prefer to create separate profiles for different projects (e.g. in ~/.gitconfig.d/) and then include them in the repository's config file:

    cd /path/to/repo
    git config include.path '~/.gitconfig.d/myproject.conf'
    

    This works well if you need to use the same set of options in multiple repos that belong to a single project. You can also set up shell aliases or a custom Git command to manipulate the profiles.

提交回复
热议问题