πŸ€” What?

You are working with multiple teams. You are using a different GitLab/GitHub account for each team. For example:

| Team 1 | username@team1.com | ssh_key_1 | | Team 2 | username@team2.com | ssh_key_2 | | Personal | username@gmail.com | ssh_key_0 |

Since the SSH key is unique and cannot be used across accounts. How to manage multiple accounts without hassle?

πŸš€ How?

This is done using Git includeIf. Let’s say in addition to my personal GitLab account, I have a separate account for my Mrrakc organization with mrrakc@gmail.com.

Project Directory Structure

# Home
|- .config
|-- git
|---- config
|- .ssh

# Mrrakc
|- Workspace
|-- Mrrakc
|---- maps
|---- blog
|---- games
|---- .config
|------ git
|--------- allowed_signers
|--------- config
|------ ssh

In the main git configuration file. We include the Mrrakc git config when current directory is under Workspace/Mrrakc.

# ~/.config/git/config
[user]
	email = <personal_email>
	name = <personal_name>
	signingkey = <signing-key>

[includeIf "gitdir:/home/guru/Workspace/Mrrakc/**"]
  path = /home/guru/Workspace/mrrakc/.config/git/config

Then configure git to use specific configuration for SSH and Signing for all Mrrakc projects. (Projects under ~/Workspace/Mrrakc)

# ~/Workspace/Mrrakc/.config/git/config

[user]
  email = mrrakc@gmail.com
  name = Mrrakc
  signingkey = /home/guru/Workspace/Mrrakc/.config/ssh/id_rsa.pub

# Custom SSH key
[core]
  sshCommand = ssh -i /home/guru/Workspace/Mrrakc/.config/ssh/id_rsa -F /dev/null -o IdentitiesOnly=yes

[gpg]
  format = ssh

# Allowed signing keys
[gpg "ssh"]
  allowedSignersFile = /home/guru/Workspace/Mrrakc/.config/git/allowed_signers
# ~/Workspace/Mrrakc/.config/git/allowed_signers

mrrakc@gmail.com ssh-ed25519 <ssh-key-id> mrrakc@gmail.com