RSS Amplifier

Duy NG · Jan 19, 2025

[Note] Managing multiple Git accounts

0
Sign in to vote or save

This page cannot be shown here. You can still read it on the original site — the toolbar below keeps your place in the directory.

Backend Engineer · Open source · Terminal

Managing multiple Git accounts

Working with multiple Git accounts (e.g., work, personal, open-source) can be tricky. Here’s how I manage them seamlessly using conditional includes in .gitconfig.

Global .gitconfig setup

Add conditional includes to the global .gitconfig:

[includeIf "gitdir:~/projects/company1/"]
    path = ~/projects/company1/.gitconfig

[includeIf "gitdir:~/projects/company2/"]
    path = ~/projects/company2/.gitconfig

[includeIf "gitdir:~/projects/oss/"]
    path = ~/projects/oss/.gitconfig

Local .gitconfig

In each project’s .gitconfig, specify the user and SSH key.

Here is example for ~/projects/company1/.gitconfig

[user]
    name = username1
    email = name@company1.com

[core]
    sshCommand = ssh -i ~/.ssh/company1_rsa

Git will help us to automatically switch configurations based on the project directory.

Read on /notes/git-multiple-account/

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.