Effective Strategies for Maintaining Multiple GitHub Accounts

Search for a command to run...

No comments yet. Be the first to comment.
When you work with both personal and office Google Cloud accounts, it’s easy to mix up credentials on your local machine. In this guide, you’ll learn how to: Prerequisites Before you follow this guide

Best Methods for Securing Connections Between GCS Buckets and GCP VMs

If you are a Coffee lover working hard and missing coffee so The Coffee House Theme for Ghostty terminal is here to add style, comfort, and a caffeine-inspired vibe to your terminal. Key Changes of the Coffee House Theme 1. Coffee-Inspired Palette Th...

This blog post introduces a Bash script designed to simplify Linux system updates across various distributions. With this script, you can: Perform system updates with a single command. Schedule updates using cron jobs for convenience. Log every up...

Managing multiple GitHub accounts can be a hassle, especially when balancing personal, work, and client projects. This guide will help you streamline the process by automating commits and pushes.
To maintain multiple GitHub account in your system best way to do is create separate for each of them such as
mkdir -p ~/Personal
mkdir -p ~/Work
mkdir -p ~/client1
Here in each of folder we can create work in each folder and each folder can align to correct git credentials
nano ~/.gitconfig-personal
Add the following content. Replace the email with your actual personal email.
[user]
name = your-personal-github-username
email = your-personal-email@example.com
nano ~/.gitconfig-work
Add the following content. Replace the email with your actual work email.
[user]
name = your-work-github-username
email = your-work-email@example.com
nano ~/.gitconfig-client-1
Add the following content. Replace the email with your actual client1 email.
[user]
name = your-client1-github-username
email = your-client1-email@example.com
Now, edit your main ~/.gitconfig file to automatically use the correct config file based on the project's path.
Open ~/.gitconfig and make it look like this. This sets your personal account as the default and creates rules for your work directory.
Usually when your are working on work laptop or system you should keep default as work username and email then Set your work account as the default on your work laptop to ensure commits use the correct credentials
# This is your default (work) user config
[user]
name = your-work-github-username
email = your-personal-email@example.com
# --- Automatic Profile Switching ---
# If the project is inside ~/dev/work/, use the work config
[includeIf "gitdir:~/Personal"]
path = ~/.gitconfig-personal
[includeIf "gitdir:~/client1"]
path = ~/.gitconfig-client1
With this setup, Git will automatically use the correct name and email for your commits.
To push and pull from different accounts on the same service (like GitHub), you need separate SSH keys.
Create a unique SSH key for each account.
# Personal key
ssh-keygen -t ed25519 -C "your-personal-email@example.com" -f ~/.ssh/id_ed25519_personal
# Work key
ssh-keygen -t ed25519 -C "your-work-email@example.com" -f ~/.ssh/id_ed25519_work
# Client key
ssh-keygen -t ed25519 -C "your-client1-email@example.com" -f ~/.ssh/id_ed25519_client1
If you’re thinking what that id_ed25519: This is the cryptographic algorithm used to generate the key. Ed25519 is a modern, secure, and fast choice for SSH keys.
When prompted for a passphrase, you can either enter one for extra security or press Enter to skip.
Copy the contents of each public key (.pub file) and add them to your corresponding GitHub accounts in Settings > SSH and GPG keys.

Copy the contents of each public key (.pub file) and add them to your corresponding GitHub accounts in Settings > SSH and GPG keys.
# Copy your personal public key
pbcopy < ~/.ssh/id_ed25519_personal.pub
# Copy your work public key
pbcopy < ~/.ssh/id_ed25519_work.pub
# Copy your client public key
pbcopy < ~/.ssh/id_ed25519_client1.pub
Create or edit your SSH config file at ~/.ssh/config. This file tells your computer which key to use for which account.
nano ~/.ssh/config
Add the following configuration:
# Personal GitHub account
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
IdentitiesOnly yes
# Work GitHub account
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
IdentitiesOnly yes
# Client1 GitHub account
Host github.com-client1
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_client1
IdentitiesOnly yes
From now on, when you clone a repository, you must use the custom host you just defined. This ensures the correct SSH key is used.
To clone a personal repo:
git clone git@github.com-personal:your-personal-username/personal-repo.git
To clone a work repo:
git clone git@github.com-work:your-work-username/work-repo.git
To clone a client1 repo:
git clone git@github.com-work:your-client1-username/client1-repo.gitYour
system is now fully configured to manage both accounts automatically.
Finally, navigate to the local repository you want to fix and tell it to use the new SSH URL.
For a personal repository (like your personal project):
cd ~/Personal/vazid
git remote set-url origin git@github.com-personal:your-personal-usernmae/repo.git
For a work repository:
cd ~/Work/my-work-project
git remote set-url origin git@github.com-work:your-work-username/work-repo.git
For a work repository:
cd ~/client1/my-work-project
git remote set-url origin git@github.com-client1:your-client1-username/client1-repo.git
You are now fully set up to push and pull using the correct account automatically.
Thank You