What steps must I take to consistently push to two Github accounts using SSH?

后端 未结 1 631
日久生厌
日久生厌 2020-12-11 11:54

I commit to Github for work and for personal use. For the last two months I have consistently had trouble each and every time I switch github contexts. Every night (and ev

相关标签:
1条回答
  • 2020-12-11 12:22

    The way you link a remote repo and different ssh keys in Git is through the remote url.
    Change those urls like so:

     cd /path/to/my/work/repo
     git remote set-url origin workgh:myWorkLogin/myWorkrepo.git
    
     cd /path/to/my/perso/repo
     git remote set-url origin persgh:myPersoLogin/myPersorepo.git
    

    See "How to work on personal GitHub repo from office computer whose SSH key is already added to a work related GitHub account?" as a full example.
    Your ~/.ssh/config will reference the right ssh key for each url:

    # Personal GitHub
    Host persgh
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa_perso
    
    # Work GitHub
    Host workgh
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa_work
    

    Don't use "github.com" as a "Host": using an special name for the Host key is more explicit and indicates this is an ssh url you have to resolve through a ~/.ssh/config file.

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