Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use GitHub and GitLab on one machine?

I have accounts in GitHub and GitLab. I generated and added an RSA key to my account in GitLab, but now I need to work with GitHub on a second project.

I know that GitLab and GitHub both use git. Please tell me if it's possible to use GitHub and GitLab on one machine?

like image 917
Uladz Kha Avatar asked Nov 11 '16 13:11

Uladz Kha


People also ask

Can I use same key for GitHub and GitLab?

Of course you can, the services don't cross-check against each other to tell if a key is in use elsewhere, but as VonC points out, you probably shouldn't.

Is GitLab separate from GitHub?

GitLab used to host its services on Microsoft Azure, but moved to Google Cloud Platform after Microsoft acquired GitHub.


2 Answers

Yes you can, you can share the same key between them both (ssh key) or create a new one per git server.

Create a SSH config file

When you have multiple identity files(in your case one for gitlab and one for github) , create a SSH config file to store your various identities.

The format for the alias entries use in this example is:

Host alias    HostName github.com    IdentityFile ~/.ssh/identity 

To create a config file for two identities (workid and personalid), you would do the following:

Open a terminal window. Edit the ~/.ssh/config file.  

If you don't have a config file, create one.
Add an alias for each identity combination for example:

Host github HostName github.com  IdentityFile ~/.ssh/github  Host gitlab HostName gilab.com  IdentityFile ~/.ssh/gitlab 

This way you can have as many accounts as you wish each one with a different ssh key attached to it.

like image 66
CodeWizard Avatar answered Sep 22 '22 17:09

CodeWizard


To use two different you must add your SSH key to both Git servers (Bitbucket, Gitlab, or Github) and configure git with your credentials. If both accounts use the same email address you can use:

git config --global user.name "Your Name" git config --global user.email "[email protected]" 

If the accounts use different emails, you must set up each repo with a local configuration file

git config --local user.name "Your Name" git config --local user.email "[email protected]" 

The local config will overwrite the global config. So you can use a global config for the most used account.

like image 27
Antonio Avatar answered Sep 18 '22 17:09

Antonio