A cat lying on an open laptop

Manage multiple GitHub orgs with workspace-specific .gitconfig


If you work across several GitHub orgs, you end up juggling user.name, user.email, and SSH keys per repo. I keep one parent ~/.gitconfig with shared defaults and use includeIf to load a tiny override file based on where the repo lives.

Parent ~/.gitconfig

[user]
    name = Jimmy Mayfield
    email = jimmy@example.com

[core]
    editor = code --wait
    autocrlf = input

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

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

Git loads the matching include when the repository path is under that directory. Use the absolute tree you actually clone into (gitdir is path-sensitive).

Workspace overrides

Each file only holds what differs—identity, SSH, optional URL rewriting:

# ~/.gitconfig-work
[user]
    name = Jimmy Work
    email = jimmy@workorg.com

[core]
    sshCommand = ssh -i ~/.ssh/id_rsa_work -F /dev/null

[url "git@github-work:"]
    insteadOf = git@github.com:

insteadOf lets you keep normal git@github.com:org/repo.git remotes while Git rewrites them to a host alias that picks the right key.

SSH host aliases

Host github-work
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_work
    IdentitiesOnly yes

Host github-personal
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_personal
    IdentitiesOnly yes

Remotes can be git@github-work:workorg/repo.git or standard GitHub URLs with insteadOf in the workspace config.

Tips

  • Keep workspace files small—identity and SSH only unless you need commit templates or signing.
  • Do not store secrets in Git config; SSH keys stay in ~/.ssh/.
  • For one-repo quirks, a repo-local .git/config include is enough; you rarely need another global layer.

If you use an AI-assisted editor across those repos, Using Cursor IDE without overengineering shares the habits I use to keep changes reviewable.


Hero photo: Catcomputer1 by Master son, CC BY-SA 3.0.