Can I specify multiple users for myself in .gitconfig?

后端 未结 20 2335
无人及你
无人及你 2020-11-22 06:33

In my ~/.gitconfig, I list my personal email address under [user], since that\'s what I want to use for Github repos.

But, I\'ve recently s

20条回答
  •  伪装坚强ぢ
    2020-11-22 06:53

    Another option to get git to work with multiple names / emails is by aliasing git and using the -c flag to override the global and repository-specific config.

    For example, by defining an alias:

    alias git='/usr/bin/git -c user.name="Your name" -c user.email="name@example.com"'
    

    To see whether it works, simply type git config user.email:

    $ git config user.email
    name@example.com
    

    Instead of an alias, you could also put a custom git executable within your $PATH.

    #!/bin/sh
    /usr/bin/git -c user.name="Your name" -c user.email="name@example.com" "$@"
    

    An advantage of these method over a repository-specific .git/config is that it applies to every git repository when the custom git program is active. In this way, you can easily switch between users/names without modifying any (shared) configuration.

提交回复
热议问题