Setting up multiple GitLab accounts (2024)

Here’s a scenario: you want to use multiple GitLab (or GitHub, etc.) on your machine. One could be your personal account and another one you use specifically for work. You want to use different SSH keys to access the repositories in either account.

Here’s how to achieve that setup properly. For this article, let’s assume we have the two GitLab accounts:

GitLab does not allow you to use the same SSH key in multiple accounts, so you’ll have to create separate keys for each account. You can create SSH keys and add them to your SSH agent by following this guide from the GitHub Documentation.

Once you’re done, you will have two sets of SSH keys, e.g.:

  • ~/.ssh/personal_key and ~/.ssh/personal_key.pub
  • ~/.ssh/work_key and ~/.ssh/work_key.pub

Now add the SSH keys to their corresponding GitLab accounts. You may follow this guide on how to do that.

Now create the file ~/.ssh/config and add the following contents:

Host gitlab.com
HostName gitlab.com
User git
IdentityFile ~/.ssh/personal_key
Host gitlab.com-work
HostName gitlab.com
User git
IdentityFile ~/.ssh/work_key

This tells SSH to use the ~/.ssh/personal_key identity by default when interacting with gitlab.com, unless the host used is “gitlab.com-work” in which case the ~/.ssh/work_key identity will be used.

The value for the Host directive can actually be anything, I’m just following a naming convention of {original-host}-{username} to make it more memorable.

When cloning repositories from the work account, you’ll need to modify the URL’s host to match the value in the SSH config’s Host directive. For example:

# Before
$ git clone git@gitlab.com:work/repository.git
# After
$ git clone git@gitlab.com-work:work/repository.git

Updating existing repositories

If you already have a local copy of the repository and you want to update their remotes to point to your remote work repository, you can do so by updating the remote’s URL like so (assuming your remote’s name is origin):

$ git remote set-url origin [email protected]:work/repository.git

When making commits, git will look at the configs to determine the name and email that it will use as the commit’s author. This will most likely end up being your global git config. To override the global config on a per-project basis, you can do:

$ cd work-repository
$ git config user.name "Work Account"
$ git config user.email "[email protected]"

Notice the absence of the —-global flag. These configs will only be set inside repository in which they were executed. When moving to other repositories, their local git configs (or the global config if no local config is set) will be used. This will keep you from having to modify your global git config every time you go inside a git repository.

Update Dec 12, 2017 11:02 am: As pointed out by Mary Louise Hermosa in the responses, an alternative approach to setting local git configs is to use “Conditional Includes”. To use it, you need to add the following snippet to your ~/.gitconfig file:

[includeIf "gitdir:/path/to/work-repository/"]
[user]
name = Work Account
email = [email protected]

This dynamically adds/removes git configs based on which git repository you are on. An advantage of this is that you can manage git configs for different projects in one central location, the ~/.gitconfig file.

Setting up multiple GitLab accounts (2024)
Top Articles
Machine Learning in Stock Prediction: a Tech Overview
Grayscale CEO Michael Sonnenshein steps down, Goldman exec to take his place
Mickey Moniak Walk Up Song
Netr Aerial Viewer
Best Pizza Novato
Busted Newspaper Zapata Tx
³µ¿Â«»ÍÀÇ Ã¢½ÃÀÚ À̸¸±¸ ¸íÀÎ, ¹Ì±¹ Ķ¸®Æ÷´Ï¾Æ ÁøÃâ - ¿ù°£ÆÄ¿öÄÚ¸®¾Æ
Boggle Brain Busters Bonus Answers
Persona 4 Golden Taotie Fusion Calculator
C Spire Express Pay
Local Dog Boarding Kennels Near Me
Summer Rae Boyfriend Love Island – Just Speak News
Craigslist Edmond Oklahoma
The Superhuman Guide to Twitter Advanced Search: 23 Hidden Ways to Use Advanced Search for Marketing and Sales
Suffix With Pent Crossword Clue
10-Day Weather Forecast for Florence, AL - The Weather Channel | weather.com
Canvas Nthurston
Mals Crazy Crab
The BEST Soft and Chewy Sugar Cookie Recipe
Jeffers Funeral Home Obituaries Greeneville Tennessee
Red Cedar Farms Goldendoodle
Atlases, Cartography, Asia (Collection Dr. Dupuis), Arch…
683 Job Calls
Asteroid City Showtimes Near Violet Crown Charlottesville
Afni Collections
Evil Dead Rise Ending Explained
Miller Plonka Obituaries
Kristy Ann Spillane
Craigslistodessa
Greater Orangeburg
134 Paige St. Owego Ny
2430 Research Parkway
Little Caesars Saul Kleinfeld
Indiana Jones 5 Showtimes Near Jamaica Multiplex Cinemas
Japanese Pokémon Cards vs English Pokémon Cards
Where Can I Cash A Huntington National Bank Check
John F Slater Funeral Home Brentwood
Blue Beetle Movie Tickets and Showtimes Near Me | Regal
Jennifer Reimold Ex Husband Scott Porter
Craigslist List Albuquerque: Your Ultimate Guide to Buying, Selling, and Finding Everything - First Republic Craigslist
888-333-4026
Legit Ticket Sites - Seatgeek vs Stubhub [Fees, Customer Service, Security]
Ashoke K Maitra. Adviser to CMD's. Received Lifetime Achievement Award in HRD on LinkedIn: #hr #hrd #coaching #mentoring #career #jobs #mba #mbafreshers #sales…
Davis Fire Friday live updates: Community meeting set for 7 p.m. with Lombardo
Promo Code Blackout Bingo 2023
Brake Pads - The Best Front and Rear Brake Pads for Cars, Trucks & SUVs | AutoZone
Used Sawmill For Sale - Craigslist Near Tennessee
Steam Input Per Game Setting
The Plug Las Vegas Dispensary
Land of Samurai: One Piece’s Wano Kuni Arc Explained
Anthony Weary Obituary Erie Pa
Latest Posts
Article information

Author: Saturnina Altenwerth DVM

Last Updated:

Views: 6555

Rating: 4.3 / 5 (64 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Saturnina Altenwerth DVM

Birthday: 1992-08-21

Address: Apt. 237 662 Haag Mills, East Verenaport, MO 57071-5493

Phone: +331850833384

Job: District Real-Estate Architect

Hobby: Skateboarding, Taxidermy, Air sports, Painting, Knife making, Letterboxing, Inline skating

Introduction: My name is Saturnina Altenwerth DVM, I am a witty, perfect, combative, beautiful, determined, fancy, determined person who loves writing and wants to share my knowledge and understanding with you.