Skip to main content
Background Image

How I manage Git accounts

·357 words·2 mins
kk
Author
kk
I duck around and find out

Imagine this - you have 2 different GitHub accounts, one personal and one for work. How do you manage them seamlessly and push without having to reconfigure git every single time?

Setup
#

Step 1 - Create two SSH keys
#

ssh-keygen -t ed25519 -C "you@personal.com" -f ~/.ssh/id_ed25519_personal
ssh-keygen -t ed25519 -C "you@work.com" -f ~/.ssh/id_ed25519_work

Step 2 - Add both keys to the SSH agent
#

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519_personal
ssh-add ~/.ssh/id_ed25519_work

Step 3 - Add public keys to GitHub
#

  • Personal GitHub → Settings → SSH Keys
  • Work GitHub → Settings → SSH Keys

Step 4 - Configure SSH to use the right key per host
#

~/.ssh/config

Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_personal

Host github.com-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_work

Step 5 - Clone using the correct host alias
#

  • Personal repos: git clone git@github.com:username/repo.git
  • Work repos: git clone git@github.com-work:company/repo.git

Git identity per directory
#

From here you can either set user.name and user.email per repo, or use ~/.gitconfig with conditional includes to handle it automatically based on directory.

Here’s an example:

~/.gitconfig

[user]
    name = Pro696969
    email = krishnakumaarmc@gmail.com
    signingkey = 338C800952DA89BF

[core]
    editor = nvim

[init]
    defaultBranch = main

[pull]
    rebase = true

[commit]
    gpgsign = true

[tag]
    gpgSign = true

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

[gpg]
    program = gpg

~/.gitconfig-work

[user]
    name = Krishna Kumar
    email = krishna@company.co
    signingkey = 60A435C9D2391E0A

[commit]
    gpgsign = true

[pull]
    rebase = true

Any repo under ~/work/ will automatically pick up the work identity. Everything else uses the global config.

Signing commits with GPG
#

Step 1 - Generate a GPG key
#

gpg --full-generate-key

Step 2 - Get the key ID
#

gpg --list-secret-keys --keyid-format=long

Step 3 - Add the GPG key to GitHub
#

GitHub (work) → Settings → SSH and GPG keys → New GPG key

Step 4 - Update ~/.gitconfig-work
#

Add the signingkey value from Step 2 to the [user] block, as shown in the config above.

Verifying the setup
#

Run these inside both a personal repo and a work repo to confirm the right identity is being picked up:

git config user.email
git config user.signingkey