Skip to content
$ gitswitch
Nord
★ star

Open Source + Work

This guide covers managing separate GitHub accounts for open source work and day job.

You want:

  • Work account — for company repos, closed-source projects
  • OSS account — for personal GitHub projects, public contributions, open source

Different SSH keys, different GitHub accounts, different emails.

Terminal window
# Work SSH key
ssh-keygen -t ed25519 -f ~/.ssh/id_work -C "alice@company.com"
# OSS SSH key
ssh-keygen -t ed25519 -f ~/.ssh/id_oss -C "alice@github.com"

Work GitHub account:

  1. Go to https://github.com/settings/keys
  2. Add ~/.ssh/id_work.pub
  3. Test: ssh -T git@github.com (should auth as work account)

OSS GitHub account:

  1. Log into your personal GitHub account
  2. Go to https://github.com/settings/keys
  3. Add ~/.ssh/id_oss.pub
  4. Test: ssh -T git@github.com (should auth as OSS account)
Terminal window
# Work profile
gitswitch add work "Alice Smith" alice@company.com \
--ssh-key ~/.ssh/id_work \
--gh-user alice-work
# OSS profile
gitswitch add oss "Alice" alice@github.com \
--ssh-key ~/.ssh/id_oss \
--gh-user alice-oss
Terminal window
# Working on company project
cd ~/work/internal-api
gitswitch work
# Now commits show alice@company.com, using id_work SSH key
# Working on open source
cd ~/projects/my-library
gitswitch oss
# Now commits show alice@github.com, using id_oss SSH key

If you’ve run gitswitch install:

Terminal window
cd ~/work/internal-api
# gitswitch: this repo usually uses work — switch? [y/N]
cd ~/projects/my-library
# gitswitch: this repo usually uses oss — switch? [y/N]

Pin the repos for permanent association:

Terminal window
cd ~/work/internal-api
gitswitch pin work
cd ~/projects/my-library
gitswitch pin oss
Terminal window
# Fork on GitHub UI as your OSS account
# Clone your fork
git clone git@github.com:alice-oss/external-project.git
cd external-project
Terminal window
gitswitch oss
# Verify
gitswitch current
# → oss / alice@github.com
Terminal window
git checkout -b add-cool-feature
git add .
git commit -m "Add cool feature"
# Commit attributed to alice@github.com
Terminal window
git push origin add-cool-feature
# Push from correct account (using id_oss)

Go to GitHub and create PR. Your OSS account shows as contributor.

Terminal window
git clone git@github.com:company/internal-api.git
cd internal-api
Terminal window
gitswitch work
# Verify
gitswitch current
# → work / alice@company.com
Terminal window
git checkout -b fix/critical-bug
git add .
git commit -m "Fix critical bug"
# Commit attributed to alice@company.com
Terminal window
git push origin fix/critical-bug
# Push from correct account (using id_work)

Create PR on company GitHub. Your work account shows as contributor.

If you use gh (GitHub CLI), it respects the GitHub account switch:

Terminal window
# As OSS account
gitswitch oss
gh repo list
# Lists your personal repos
gh pr create --title "My feature" --body "..."
# Creates PR from OSS account
# Switch to work
gitswitch work
gh repo list
# Lists company repos
gh pr create --title "Fix" --body "..."
# Creates PR from work account
Terminal window
# My work laptop has both company and personal repos
cd ~/work/internal-project
gitswitch work
# But also:
cd ~/work/side-projects/oss-contrib
gitswitch oss
# Switch to OSS identity before contributing
Terminal window
# Check work PR
gitswitch work
gh pr list --repo company/internal-api
# Check OSS issues
gitswitch oss
gh issue list --repo my-project/repo

Keeping work and personal GitHub notifications separate

Section titled “Keeping work and personal GitHub notifications separate”

With both accounts authenticated and gh support, you can:

Terminal window
gitswitch work
gh notification list
# Shows work notifications
gitswitch oss
gh notification list
# Shows OSS notifications

Accidentally committed work code to OSS identity

Section titled “Accidentally committed work code to OSS identity”

If you forgot to switch before committing:

Terminal window
# Check current identity
gitswitch current
# → wrong identity
# Switch to correct one
gitswitch work
# Amend the commit to fix author
git commit --amend --reset-author

If SSH fails:

Terminal window
# Verify correct identity is active
gitswitch current
# Test SSH directly
ssh -T git@github.com
# Should show you're authenticated as that account
# Check git's SSH config
git config --global core.sshCommand

If you pushed to OSS account but meant work account:

Terminal window
# Check current identity
gitswitch current
# If wrong, switch
gitswitch work
# The commit is already pushed, but future commits use right account
# You can ask GitHub to change PR owner or push from correct account

Managing notifications across accounts can be overwhelming:

  1. Use GitHub’s notification settings
  2. Label repos by account in local naming
  3. Create aliases for quick switching
Terminal window
alias gsw='gitswitch work'
alias gso='gitswitch oss'
gsw # Quick switch to work
gso # Quick switch to OSS

Automatically switch based on directory:

Terminal window
# Add to ~/.zshrc
function cd() {
builtin cd "$@"
if [[ $PWD == *"/work/"* ]]; then
gitswitch work 2>/dev/null
elif [[ $PWD == *"/projects/"* ]]; then
gitswitch oss 2>/dev/null
fi
}

Now switching directories automatically suggests the right identity.

Multi-account GitHub
Quick Start
Shell Integration