Max Max - 1 month ago 5
Git Question

git setup for multiple repos on same server

Probably a simple question, but I am at a loss here...

In github one can add a deployment key for each repository which only gives access to that single repository.

But for one client I have two projects managed with git on the same server (project A and project B). If I use the public key for project A, github tells me I cant use it as a deployment key for project B and vice versa.

How can I create another public key and setup git to use one key for project A and the other one for project B?

Answer

The ssh way to do this would be using ~/.ssh/config, creating a hostname alias and accessing github with different hostnames for both projects. I have no idea whether there is a git config (or git remote) way too.

Host a.github.com
HostName github.com
User git
IdentityFile ~/.ssh/project-a-id_rsa

Host b.github.com
HostName github.com
User git
IdentityFile ~/.ssh/project-b-id_rsa

Then use a.github.com:user/project-a.git or b.github.com:user/project-b.git (or similar) as your repository URLs.