Managing Multiple Git Identities: A Seamless Workflow for Personal and Work Accounts

Published: (January 16, 2026 at 02:24 PM EST)
5 min read
Source: Dev.to

Source: Dev.to

Introduction

We’ve all been there: pushing code using the wrong identity (e.g. using your personal email coding_ninja1@gmail.com to commit work‑related code).

Managing multiple Git identities on a single machine is a rite of passage for every developer. Whether you’re balancing open‑source work with a 9‑to‑5 or juggling different freelance clients, it’s incredibly easy for your professional identities to start overlapping or for you to lose track of which “hat” you’re wearing at any given moment.

In this post I will walk you through a two‑step evolution to solve this once and for all:

  1. The SSH Foundation – Set up unique SSH keys for different platforms (GitHub vs. Bitbucket). This secures your connection, but you’ll still have to remember to set user.email manually for each new repo.
  2. The Secret Sauce (Git Conditional Includes) – Make Git context‑aware so your machine automatically swaps name and email based on the folder you’re working in.

By the end of this guide you’ll have a “set it and forget it” system that keeps your professional work professional and your personal projects personal.

Step 1: The SSH Foundation

What is SSH?

SSH (Secure Shell) is a protocol that lets your computer communicate securely with a server over an unsecured network. Instead of typing a username and password every time you push code, you use a key pair:

  • Public key – shared with Bitbucket/GitHub.
  • Private key – stays on your machine (never shared).

1️⃣ Generate New SSH Keys

Open a terminal and create a key for each account (skip if you already have one).

Work (Bitbucket)

ssh-keygen -t ed25519 -C "work.email@acme.com" -f ~/.ssh/id_ed25519_bitbucket

Personal (GitHub)

ssh-keygen -t ed25519 -C "personal.email@gmail.com" -f ~/.ssh/id_ed25519_github

When prompted for a passphrase you can add one or leave it blank.
This creates the files id_ed25519_bitbucket (and .pub) and id_ed25519_github (and .pub).

Why ed25519?

  • Security – higher security level than RSA with a smaller key size.
  • Performance – faster generation and verification, making Git feel snappier.
  • Collision resistance – mathematically more resistant to certain attacks.

2️⃣ Configure Your SSH config File

The ~/.ssh/config file acts as a traffic controller. Git will automatically pick the right key when you talk to GitHub or Bitbucket.

# Personal Account (GitHub)
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_github

# Work Account (Bitbucket)
Host bitbucket.org
    HostName bitbucket.org
    User git
    IdentityFile ~/.ssh/id_ed25519_bitbucket

Open (or create) the file with nano ~/.ssh/config (or your favourite editor) and paste the block above.

3️⃣ Add the Public Keys to Their Platforms

GitHub

# Show the public key
cat ~/.ssh/id_ed25519_github.pub
  1. Copy the output.
  2. Log in to GitHub → SettingsSSH and GPG keysNew SSH key.
  3. Paste the key and save.

Bitbucket

cat ~/.ssh/id_ed25519_bitbucket.pub
  1. Copy the output.
  2. Log in to Bitbucket → Personal SettingsSSH KeysAdd key.
  3. Paste the key and save.

4️⃣ Clone and Set Up Local Identity

Global (default) Identity

Most developers set their personal account as the global default so side projects work out‑of‑the‑box:

git config --global user.email "personal.email@gmail.com"

Every repository you create or clone will inherit this email unless you override it locally.

Local Override for a Work Repository

  1. Clone the repository using the SSH URL (the config will pick the correct key):

    git clone git@bitbucket.org:acme-corp/project-alpha.git
  2. Set the local identity inside the cloned repo:

    cd project-alpha
    git config user.name "Your Name"
    git config user.email "work.email@acme.com"

Now commits in this repo will use the work email, while all other repos keep the personal email.

The Manual Burden

The approach above works, but there’s a catch: you have to remember to run the git config commands for every single work repo you clone. Forgetting the step means you’ll accidentally commit with the wrong email.

The next part of the guide (the “Secret Sauce”) will show you how to automate this with Git’s conditional includes, eliminating the manual step entirely. Stay tuned!

Git Conditional Includes

“You’ll end up pushing professional code with your personal ‘default base’ email.”

Note: This manual overhead is exactly why we use Conditional Includes — to make this switch happen automatically so you never have to think about it again.

Step 2: Git Conditional Includes

Now your computer can “talk” to both GitHub and Bitbucket without asking for a password. However, there is still one major problem: SSH handles the connection, but Git handles the name. Even if you use your work SSH key to push to Bitbucket, Git might still label your commits with personal_email@gmail.com because of your global settings.

Let’s fix that with the secret sauce: Git Conditional Includes.

The Goal

Automate your identity so you never have to type git config user.email again. This is a “set it and forget it” strategy. By using Conditional Includes, you tell Git:

If I am working inside my Work folder, automatically swap my identity to my Acme email.

This prevents the common mistake of accidentally pushing a work commit with your personal email address.

Setting It Up (Step‑by‑step)

1. Organise Your Folders

Make sure your projects are separated by directory, e.g.:

  • ~/Documents/Personal/ – all your personal stuff or projects
  • ~/Documents/Work/ – all your work stuff or projects

2. Create a “Work‑Only” Config File

nano ~/Documents/Work/.gitconfig-work

Paste the following into .gitconfig-work:

[user]
    name = Your Name
    email = work.email@acme.com

Save and exit (Ctrl+O, Enter, Ctrl+X).

nano ~/.gitconfig

Add this logic at the very bottom of the file:

# Default/Personal Identity
[user]
    name = Your Name
    email = personal.email@gmail.com

# Conditional Include: If the path starts with ~/Documents/Work/
[includeIf "gitdir:~/Documents/Work/"]
    path = ~/Documents/Work/.gitconfig-work

Save and exit.

How It Works

When you run a Git command, Git checks your current directory:

  • If you are in ~/Documents/Personal/repo, it uses the global email.
  • If you are in ~/Documents/Work/acme-project, the includeIf trigger activates and overwrites the global email with the one defined in .gitconfig-work.

Verifying the Setup

  1. Navigate into a repository inside your Work folder.

  2. Run:

    git config user.email

    It should output work.email@acme.com.

  3. Move to a folder outside “Work” and run the same command.
    It should output your personal email.

Conclusion

By combining SSH Config (for secure access) and Conditional Includes (for automated identity), you’ve built a professional‑grade development environment. No more accidental commits, no more “unrecognised user” errors, and zero manual setup for new repositories.

Back to Blog

Related posts

Read more »

Getting started with Git and GitHub.

Exploring new learning curves and opportunities isn’t something I thought I would ever do in 2026. In this post I share the lessons I learned during the first w...