пятница, 21 ноября 2014 г.

How to use multiple GitHub accounts (TortoiseGit)

Untitled Document.md

Let's imagine that you have two accounts in some source control system (such as Github or Bitbucket). And you wondering, how to use them both in your everyday live. I will show you how: It turned out that it's not so simple (of course). At first you need to decide, which tool are you using to communicate with server. It can be just simple git console, or ui tools, in my case it was TortoiseGit.

Main problem with two accounts is that if you use SSH authentication, git cannot decide, which key to use to communicate with server (host name is the same for both users). So initial settings is: you have two accounts with repos:

git@github.com:MartyMcFly/hoverboard.git
git@github.com:DocBrown/time-machine.git

And you have two private SSH keys to both accounts:

~/.ssh/marty_key
~/.ssh/doc_key

When you try to push to some repo you will get access denied on one of them. To fix it you will need:

For Git console and ssh client

Great solution described here. In short you will need to add config file to .ssh directory with:

#MartyMcFly account
Host github.com-MartyMcFly
    HostName github.com
    User git
    IdentityFile ~/.ssh/marty_key

#DocBrown account
Host github.com-DocBrown
    HostName github.com
    User git
    IdentityFile ~/.ssh/doc_key

Actually you can find more information in gist conversation above. I never tested it because i use TortoiseGit

For TortoiseGit and Putty

If you use TortoiseGit, solution above will not help you. Although you can specify private key for each repo - you will get error with access denied. Your settings may looks like alt text

Error happens because if you load keys to Peageant (as in picture below) alt text

Peageant will load firts key in list for specific host. To fix this go you can read this thread or TortoiseGit documentation. In summary you will need to open Putty (download) and

  1. Paste github.com in Host.Name in Sessions menu alt text
  2. Go to Connection -> Auth and specify path to SSH key alt text
  3. Return back to Session menu, specify session name and click Save alt text
  4. Change url in repository settings (by right clicking on repository and then TortoiseGit -> settings -> Git -> Remote ). Change

    git@github.com:MartyMcFly/hoverboard.git

    to

    git@marty_github:MartyMcFly/hoverboard.git

  5. Repeat for all accounts.
  6. Enjoy!

Комментариев нет:

Отправить комментарий