Pat David Avatar
ABOUT ARCHIVE
Theme

Using Multiple GitLab Accounts

I got a new job (more on that later)!

One of the things I needed to setup is multiple GitLab accounts. I want to continue using my personal account but I also want to automatically be able to use a new work account as well.

My personal repos were in ~/personal/ and work was (gasp!) ~/work/.

I tried out a few different things I read online such as this article on Medium by Arnelle Balane that uses includeIf in .gitconfig to change the user configs based on the gitdir. It didn’t work for me, however.

In the end what ended up working for me was from this stackoverflow comment:

https://stackoverflow.com/a/63308511

Where I could load a separate .gitconfig based in each of my directories. Then I could include configurations specific to each workflow in general (personal vs. work).

For example ~/personal/.gitconfig looks like this:

[user]
  name = Pat David
  email = patdavid@gmail.com
[core]
  sshCommand = "ssh -i /home/pat/.ssh/gitlab/id_rsa"

The sshCommand ... line was the magic sauce that lets me tell git which keys to load when working with and personal repos. I have a similar one for my work directory as well.

Then in my global .gitconfig at the end I have:

...
[includeIf "gitdir:/home/pat/work/"]
  path = /home/pat/work/.gitconfig
[includeIf "gitdir:/home/pat/personal/"]
  path = /home/pat/personal/.gitconfig

to load the appropriate information when needed. Easy peasy!

* Note that I believe you’ll need at least Git version 2.13 for the includeIf directive.


Filed under: git, workflow

Share this on: Twitter | Facebook