How to configure multiple github accounts on your computer?

后端 未结 1 1375
孤城傲影
孤城傲影 2020-12-17 08:30

So, I have my work computer and that is connected to my GitHub Enterprise Account (github.company.com) on the terminal. Now I want to set up my personal account

1条回答
  •  无人及你
    2020-12-17 08:59

    Detailed steps to use two GitHub accounts on the same PC as below:

    1. Create SSH key for the github.company.com account

    If you already added the SSH key to your github.company.com account, then skip this step.

    First, use ssh-keygen to create id_rsa and id_rsa.pub in C:\Users\username\.ssh.

    Then, add the content of id_rsa.pub file as a SSH key in github.company.com account.

    2. Create SSH Key for your personal account github.com

    Use ssh-keygen -t rsa -C "email address for the personal github account", and save the key in /c/Users/username/.ssh/id_rsa_personal.

    Now add the content of id_rsa_personal.pub file as a SSH Key in your personal GitHub account.

    3. Config the two SSH Keys

    In C:\Users\username\.ssh diectory, create a config file with below content:

    Host github.company.com
      HostName github.company.com
      User git
      IdentityFile ~/.ssh/id_rsa
    Host github-personal
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa_personal
    

    4. Work with the two GitHub accounts by SSH protocol

    You can clone your github.company.com account by:

    git clone git@github.company.com:companyaccountname/reponame
    

    And then add the personal account as a remote in the local repo by:

    git remote add personal git@github-personal:personalaccountname/reponame
    

    To get the file from personal account to company repo by below commands:

    git merge upstream master --allow-unrelated-histories
    # make changes
    git add .
    git commit -m 'add the changes from peronal repo'
    git push origin master
    

    To commit/push changes from local company repo by the committer of the personal repo, you just need to re-config the username and email before committing changes in the local repo:

    git config user.name 
    git config user.email 
    

    When you want to commit changes with the company account, just re-config username and email again before committing changes.

    0 讨论(0)
提交回复
热议问题