Blog
2
Gists
3
Slide
4
GitHubLinkedInEmail

© 2025 Milind Mishra.

Managing Two Git Profiles on the Same Machine

4 months ago
Git
ssh-keys
Managing Two Git Profiles on the Same Machine

Working with two Git profiles on the same machine might sound straightforward, but it can quickly turn into a frustrating experience. I faced this challenge when trying to maintain separate mac os profiles for personal and work projects. Here’s why maintining in the same profile was necessary for me and how I managed to resolve the issues.


The Pain of getting the permissions mixed between Profiles

As a developer juggling personal side projects and professional work, I found myself constantly switching between the tow user profiles. This led to several issue of Mixed Permissions I used to work on the different profile for work and personal projects, and used to struggle resetting permissions for brew, node and other binaries. These challenges forced me to find a better solution to manage multiple Git profiles on my machine.


Setting Up Two Git Profiles

To solve this, I set up separate SSH keys and configurations for each profile. Here’s how you can do it too:

1. Create SSH Keys for Each Account

Generate separate SSH keys for your personal and work accounts and add them to respective github accounts :

For macOS and Linux:

cd ~/.ssh
ssh-keygen -t rsa -C "[email protected]" -f "github-personal"
ssh-keygen -t rsa -C "[email protected]" -f "github-work"

2. Add SSH Keys to the SSH Agent

Add the generated keys to your SSH agent:

For macOS:

ssh-add --apple-use-keychain ~/.ssh/github-personal
ssh-add --apple-use-keychain ~/.ssh/github-work

Fir Linux:

ssh-add ~/.ssh/github-personal
ssh-add ~/.ssh/github-work

3. Configure SSH for Multiple Accounts

Edit the SSH config file to define host aliases for each account:
nano ~/.ssh/config

# Personal account
Host github-personal
    HostName github.com
    User git
    IdentityFile ~/.ssh/github-personal

# Work account
Host github-work
    HostName github.com
    User git
    IdentityFile ~/.ssh/github-work

4. Use Correct Accounts for Repositories

When cloning repositories, use the appropriate host alias:

  • For personal projects:
    git clone git@github-personal:username/repo.git

  • For work projects:
    git clone git@github-work:username/repo.git


If you’ve struggled with managing multiple Git accounts on the same machine, I hope this guide helps you as much as it helped me.