Can I specify multiple users for myself in .gitconfig?

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

    Here are the complete steps after reading many answers here

    How to set up Multiple SSH Keys settings for different github account

    You might want to start checking your currently saved keys

    $ ssh-add -l
    

    If you decide to delete all cached keys before (optional, carefull about this)

    $ ssh-add -D
    

    Then you can create a ssh pub/priv key linked to each email/account that you wish/need to use

    $ cd ~/.ssh
    $ ssh-keygen -t rsa -C "work@company.com" <-- save it as "id_rsa_work"
    $ ssh-keygen -t rsa -C "pers@email.com" <-- save it as "id_rsa_pers"
    

    After performing this commands you will have the following files created

    ~/.ssh/id_rsa_work      
    ~/.ssh/id_rsa_work.pub
    
    ~/.ssh/id_rsa_pers
    ~/.ssh/id_rsa_pers.pub 
    

    Make sure authentication agent is running

    $ eval `ssh-agent -s`
    

    Add the generated keys as following (from the ~/.ssh folder)

    $ ssh-add id_rsa_work
    $ ssh-add id_rsa_pers
    

    Now you can check your saved keys again

    $ ssh-add -l
    

    Now you need to add the generated public keys to your github/bickbuket server Acces Keys

    Clone each of the repos to different folders

    Go to the folder where the user work will work and execute this

    $ git config user.name "Working Hard"
    $ git config user.email "work@company.com" 
    

    Just to see what this does check the contents of the ".git/config"

    Go to the folder where the user pers will work and execute this

    $ git config user.name "Personal Account"
    $ git config user.email "pers@email.com" 
    

    Just to see what this does check the contents of the ".git/config"

    After all this you will be able to commit your personal and work code by just switching between those two folders

    In case you are using Git Bash and need to generate ssh keys under Windows follow this steps:

    https://support.automaticsync.com/hc/en-us/articles/202357115-Generating-an-SSH-Key-on-Windows

提交回复
热议问题