Can I specify multiple users for myself in .gitconfig?

后端 未结 20 2772
无人及你
无人及你 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 07:02

    Maybe it is a simple hack, but it is useful. Just generate 2 ssh keys like below.

    Generating public/private rsa key pair.
    Enter file in which to save the key (/Users/GowthamSai/.ssh/id_rsa): work
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in damsn.
    Your public key has been saved in damsn.pub.
    The key fingerprint is:
    SHA256:CrsKDJWVVek5GTCqmq8/8RnwvAo1G6UOmQFbzddcoAY GowthamSai@Gowtham-MacBook-Air.local
    The key's randomart image is:
    +---[RSA 4096]----+
    |. .oEo+=o+.      |
    |.o o+o.o=        |
    |o o o.o. +       |
    | =.+ .  =        |
    |= *+.   S.       |
    |o*.++o .         |
    |=.oo.+.          |
    | +. +.           |
    |.o=+.            |
    +----[SHA256]-----+
    

    Same way create one more for personal. So, you have 2 ssh keys, work and company. Copy work.pub, work, personal.pub, personal to ~/.ssh/ Directory.

    Then create a shell script with the following lines and name it as crev.sh (Company Reverse) with the following content.

    cp ~/.ssh/work ~/.ssh/id_rsa
    cp ~/.ssh/work.pub ~/.ssh/id_rsa.pub
    

    Same way, create one more called prev.sh (Personal Reverse) with the following content.

    cp ~/.ssh/personal ~/.ssh/id_rsa
    cp ~/.ssh/personal.pub ~/.ssh/id_rsa.pub
    

    in ~/.bashrc add aliases for those scripts like below

    alias crev="sh ~/.ssh/crev.sh"
    alias prev="sh ~/.ssh/prev.sh"
    source ~/.bashrc
    

    Whenever you wanna use company, just do crev, and if you wanna use personal do prev :-p.

    Add those ssh keys to your GitHub accounts. Make sure, you don't have id_rsa generated previously, because those scripts will overwrite id_rsa. If you have already generated id_rsa, use that for one of the accounts. Copy them as personal and skip the generation of personal keys.

提交回复
热议问题