One Key, Two Accounts

Two GitHub accounts on one machine. Every commit Verified.

Keep your personal and work GitHub on the same laptop. Switch with one command, sign every commit with one GPG key, and let each folder pick the right email. No SSH aliases, no extra tools.

  • gh 2.40+
  • GnuPG 2.2+
  • Git 2.37+
  • Linux, macOS and Windows
you-personalyou@personal.dev
you-workyou@company.com
One GPG key
3439 F5BC … 119A EE81
you@personal.dev
you@company.com
Fix typo in READMEa1f9e2c · ~/codeVerified
Add health check4f2c1a9 · ~/workVerified

#What you end up with

Two GitHub accounts, personal and work, share one GPG key that holds both emails. Commits from either account show Verified.
  • Both accounts logged in with the GitHub CLI (gh). You switch with one command and never paste tokens.
  • One GPG key that holds both of your emails, so commits are signed for either account.
  • Verified next to every commit you push, on both accounts.
  • The right email picked automatically: work repos use your work email, everything else uses your personal one.

#Before you start

You need Where
Two GitHub accounts, e.g. you-personal and you-work
One email per account, verified on that account github.com/settings/emails
git, gh (2.40+) and gpg installed install commands (Linux, macOS, Windows)
About 15 minutes

Tip: use two browser profiles (one per account). Logging in each account becomes painless, because GitHub approves a login for whichever account is signed in in the browser.

#Quick setup

#1. Log in to both accounts

gh keeps several accounts side by side. Run the login once per account, with the browser signed in as that account.

gh auth login        # personal (browser signed in as personal)
gh auth login        # work     (browser signed in as work)
gh auth setup-git    # lets git push/pull through gh, no passwords
gh auth status       # should list both accounts

Answers to pick: GitHub.com → HTTPS → Yes → Login with a web browser. Then paste the code shown in the terminal on the page that opens. Full walkthrough: Log in to two GitHub accounts

#2. Make one GPG key with both emails

The key is your digital signature. One key can carry several emails, so add both.

gpg --full-generate-key                                 # personal email, leave Comment EMPTY
gpg --list-secret-keys --keyid-format=long              # copy the long key ID (40 characters)
gpg --quick-add-uid <KEY_ID> "Your Name <you@company.com>"
gpg --check-trustdb                                     # marks the new email as yours

Expiry: choose 0 (never) or 2y. Don't type a huge value like 100y, gpg rejects it. Full walkthrough: Create one GPG key with both emails

#3. Put the key on both accounts

GitHub needs the public half of the key to check your signatures.

gpg --armor --export <KEY_ID> > key.asc

On each account, open github.com/settings/gpg/new and paste the whole file. Full walkthrough, and the terminal way with gh: Add the GPG key to GitHub

#4. Tell Git who you are and to sign everything

git config --global user.name  "Your Name"
git config --global user.email "you@personal.dev"
git config --global user.signingkey <KEY_ID>
git config --global commit.gpgsign true
git config --global tag.gpgsign true

Also add export GPG_TTY=$(tty) to ~/.bashrc / ~/.zshrc (fish: set -gx GPG_TTY (tty)) so gpg can ask for your passphrase. Full walkthrough: Make Git sign every commit

Put work repos in ~/work/ and Git uses your work email there by itself.

mkdir -p ~/work
printf '[user]\n    email = you@company.com\n' > ~/.gitconfig-work
git config --global includeIf."gitdir:~/work/".path ~/.gitconfig-work

Full walkthrough: Work email by folder

#6. Back up your key now

If your laptop dies and you have no backup, the key is gone for good. It takes 1 minute:

gpg --armor --export-secret-keys <KEY_ID> > private-key-BACKUP.asc

Copy it to a USB stick or password manager, never to a repo or cloud chat. Full guide (restore, renew, lost key): Back up your GPG key

#Every day

gh auth switch          # choose the account that owns the repo you'll push to
git commit -m "..."     # signed automatically, email picked by folder
git push

Then check the commit on GitHub: it should show Verified. More: Switch accounts and check Verified commits

These aren't required, but they save most developers trouble later.

#Check what your device already set

Some systems, distros or tools put their own Git defaults in /etc/gitconfig or ~/.gitconfig. See everything that's active and which file it comes from:

git config --list --show-origin
git config --show-origin pull.rebase     # check one setting

A value set by the system can be overridden with --global.

#Settings most developers want

Setting Command Why
Merge on pull (no rebase) git config --global pull.rebase false Some devices or tools set this to true. Then git pull rewrites your local commits, which surprises most people. false is the safe, normal default. Use true only if your team wants rebase.
Branch name main git config --global init.defaultBranch main New repos start on main, same as GitHub
Easy first push git config --global push.autoSetupRemote true git push on a new branch just works, with no --set-upstream
Clean old branches git config --global fetch.prune true Removes deleted remote branches on fetch
Sign tags too git config --global tag.gpgsign true Releases show Verified as well. Tags then need a message: git tag -m "v1.0.0" v1.0.0
Line endings, Linux/macOS git config --global core.autocrlf input Avoids "every line changed" diffs
Line endings, Windows git config --global core.autocrlf true Same, for Windows

#Privacy

  • Hide your real email. Each account has a noreply address (e.g. 12345+you@users.noreply.github.com) on settings/emails. You can use it as the commit email and add it to your GPG key too. Your real email then never appears in public history.
  • On the same page, turn on Keep my email addresses private and Block command line pushes that expose my email.

#Security

  • Turn on 2FA for both accounts: github.com/settings/security.

  • Use a passphrase on the GPG key and keep it in a password manager.

  • Never commit key files. Add this to your global gitignore:

    printf '*.asc\n*.gpg\n*.rev\n' >> ~/.gitignore_global
    git config --global core.excludesFile ~/.gitignore_global
  • Don't store tokens in plain text. gh auth setup-git already handles logins. Avoid git config credential.helper store.

  • Flag fakes. At settings/keys, turn on Flag unsigned commits as unverified, so anyone faking commits as you shows up.

#Good habits

  • Run gh auth status when unsure which account is active.
  • Run git config user.email inside a repo before the first commit, to see which email it will use.
  • If you add an email to the key later, re-upload the key to GitHub.
  • Set a calendar reminder if your key expires. Renewing takes one command (backup.md).

#Questions

Can I use two GitHub accounts on one computer?

Yes. The GitHub CLI (version 2.40 and newer) keeps several accounts logged in at once, and gh auth switch changes which one Git uses to push. Your commit email and signature are handled separately by Git, so each repo gets the right identity. The quick setup takes about 15 minutes.

Do I need SSH keys or an ~/.ssh/config with host aliases?

No. The common SSH approach needs a key per account, Host aliases in ~/.ssh/config, and edited remote URLs like git@github-work:org/repo.git in every clone. This guide uses gh over HTTPS instead: normal clone URLs, no aliases, and one command to switch. If you prefer SSH for other reasons, the author's SSH guide covers keys and config in depth.

Can the same GPG key be on two GitHub accounts?

Yes. GitHub accepts the same key on several accounts (tested in October 2026). Each account shows Verified for commits whose email is verified on that account. If GitHub ever answers "Key is already in use", use one key per account.

Does gh auth switch change my commit email?

No. gh auth switch only changes which account pushes and pulls. The email written into a commit comes from Git's config. With the work folder setup, repos in ~/work/ use your work email automatically.

Why does my commit say Unverified?

GitHub needs three things: the commit is signed, the commit email is inside your key, and that email is verified on the account holding the key. The troubleshooting page shows how to check each one.

Can I sign commits with an SSH key instead of GPG?

Yes. Git can sign with SSH keys (git config --global gpg.format ssh and user.signingkey ~/.ssh/id_ed25519.pub), and GitHub verifies them once you add the key as a Signing key at settings/ssh/new. This guide uses GPG because one key holds both emails and works for tags and every Git host the same way.

Do VS Code and JetBrains IDEs sign my commits too?

Yes. Editors that run your installed Git follow the same commit.gpgsign and user.signingkey settings. They need a graphical passphrase prompt: on Linux install a GUI pinentry such as pinentry-qt or pinentry-gnome3, on macOS use pinentry-mac.

Can I use more than two accounts?

Yes. Run gh auth login once per account, add every email to the key, and add one folder with its own includeIf block per account (step 5).

Does this work on Windows?

Yes. Git for Windows ships with gpg. Run the commands in Git Bash (install notes).

Is it safe to put my GPG key on GitHub?

You only upload the public key, which is made to be shared. Never upload or commit the private key backup (backup.md).

What happens to Verified commits when my key expires?

GitHub records the verification when you push, so commits that showed Verified keep it. Renew the key before it expires so new commits are signed too (renew).

How do I keep my real email out of public commits?

Use your account's noreply address (like 12345+you@users.noreply.github.com, shown on settings/emails) as the commit email, and add it to your key. More in privacy tips.

All questions and answers · Fix an error message