💻 Are you Using Same Machine for Work & Personal Git? Stop Mixing Your Commits!

Ever committed company code with your personal email? Or pushed a side project using your work account?
If you use one laptop for both environments, managing multiple GitHub accounts can be a headache.
Here is the cleanest, bulletproof way to separate them entirely using SSH Aliases and Git Folder Automation. No more manual switching. No more typos.
🛠️ Step 1: Create Separate SSH Keys
Generate one key for your personal account and another for work:
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_personal
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_work
Add the generated public keys to the respective GitHub accounts (Fig. 1).
Fig. 1
Then open your SSH config file (%USERPROFILE%\.ssh\config on Windows) and add:
# Personal Account
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
# Work Account
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
💡 When cloning repositories, use the alias instead of github.com (important):
git clone git@github.com-personal:username/repo.git
git clone git@github.com-work:company/repo.git
📂 Step 2: Keep Projects in Separate Folders
For ex:
D:/Personal/
D:/Work/
Keeping projects organized makes automatic profile switching possible.
🤖 Step 3: Let Git Auto-Switch Identities
Remove any global email configuration and let Git choose the correct profile based on the folder you're working in.
Open your global Git config:
git config --global --edit
Add:
# Personal projects
[includeIf "gitdir/i:D:/Personal/"]
path = ~/.gitconfig-personal
# Work projects
[includeIf "gitdir/i:D:/Work/"]
path = ~/.gitconfig-work
🗃️ Step 4: Create Your Git Profiles
Create these files in your home directory:
Windows
notepad %USERPROFILE%\.gitconfig-personal
notepad %USERPROFILE%\.gitconfig-work
macOS/Linux
touch ~/.gitconfig-personal ~/.gitconfig-work
👉 File: .gitconfig-personal
[user]
name = Your Personal Name
email = your-personal-email@gmail.com
👉 File: .gitconfig-work
[user]
name = Your Work Name
email = your-work-email@company.com
✅ Verify It Works
Inside any repository, run:
git config user.email
Git should automatically show the email associated with that folder.
🔥 Why This Setup Is Worth It
✅ No manual account switching
✅ Personal and work SSH keys stay separate
✅ Commits always use the correct name and email
✅ Easy to maintain when setting up a new machine
Save this for your next future setup. 🚀
#Git #GitHub #SoftwareEngineering #DeveloperTips #DevOps #Productivity #Programming #TechTips #WebDevelopment
