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:

  • Personal Account, username: personal, email: personal@email.com
  • Work Account, username: work, email: work@email.com

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 git@gitlab.com-work: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 "work@email.com"

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 = work@email.com

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
Trading and Profit and Loss Account - Format and Calculation
VA Underwriting Guidelines: Process and Timeline
This website is unavailable in your location. – WSB-TV Channel 2 - Atlanta
His Lost Lycan Luna Chapter 5
Jonathon Kinchen Net Worth
Shorthand: The Write Way to Speed Up Communication
877-668-5260 | 18776685260 - Robocaller Warning!
Dr Lisa Jones Dvm Married
123 Movies Black Adam
Fallout 4 Pipboy Upgrades
Progressbook Brunswick
New Mexico Craigslist Cars And Trucks - By Owner
Persona 4 Golden Taotie Fusion Calculator
Binghamton Ny Cars Craigslist
5 high school volleyball stars of the week: Sept. 17 edition
Willam Belli's Husband
Forum Phun Extra
Nhl Tankathon Mock Draft
Air Quality Index Endicott Ny
[PDF] PDF - Education Update - Free Download PDF
Sec Baseball Tournament Score
Surplus property Definition: 397 Samples | Law Insider
Reicks View Farms Grain Bids
Wiseloan Login
Ordensfrau: Der Tod ist die Geburt in ein Leben bei Gott
Craigs List Jax Fl
Kleinerer: in Sinntal | markt.de
Laveen Modern Dentistry And Orthodontics Laveen Village Az
Human Unitec International Inc (HMNU) Stock Price History Chart & Technical Analysis Graph - TipRanks.com
Capital Hall 6 Base Layout
1987 Monte Carlo Ss For Sale Craigslist
Texas Baseball Officially Releases 2023 Schedule
2008 Chevrolet Corvette for sale - Houston, TX - craigslist
Aliciabibs
Skyrim:Elder Knowledge - The Unofficial Elder Scrolls Pages (UESP)
10 games with New Game Plus modes so good you simply have to play them twice
Michael Jordan: A timeline of the NBA legend
One Main Branch Locator
Flags Half Staff Today Wisconsin
Sept Month Weather
Ferguson Employee Pipeline
Jack In The Box Menu 2022
Wunderground Orlando
Shoecarnival Com Careers
Busted Newspaper Mcpherson Kansas
Walgreens On Secor And Alexis
Arcanis Secret Santa
Identogo Manahawkin
Diamond Desires Nyc
18443168434
Blippi Park Carlsbad
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.