Multi-Git Account Setup (Personal + Work) β
Scenario: You have one machine. One brain. Two lives: Personal and Work. Git doesnβt know how to separate them. Letβs fix that.
Tools of the Trade β
- πΉ A mind that knows the terminal
- πΉ One laptop, two identities
- πΉ GitHub (or GitLab/Bitbucket β doesn't matter)
Objective β
Manage both personal and work Git accounts seamlessly on the same machine without cross-contamination.
Step 0: Check Your Setup β
bash
git --version
ssh -VStep 1: Create Your Secret Keys (SSH) β
bash
# Personal identity
ssh-keygen -t ed25519 -C "your_personal_email@example.com" -f ~/.ssh/id_ed25519_personal
# Work identity
ssh-keygen -t ed25519 -C "your_work_email@company.com" -f ~/.ssh/id_ed25519_workHit
Enterthrough prompts unless you want a passphrase.
Step 2: Add Keys to SSH Agent β
bash
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519_personal
ssh-add ~/.ssh/id_ed25519_workStep 3: Send Public Keys to GitHub β
Paste each one into GitHub settings β SSH and GPG keys.
bash
cat ~/.ssh/id_ed25519_personal.pub
cat ~/.ssh/id_ed25519_work.pubStep 4: Configure the Brain (aka ~/.ssh/config) β
bash
nano ~/.ssh/configPaste this:
ssh
# Personal GitHub
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
# Work GitHub
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_workNow SSH knows which identity to use based on the alias.
Step 5: Clone Like a Shadow β
bash
# Personal repo
git clone git@github.com-personal:yourusername/personal-repo.git
# Work repo
git clone git@github.com-work:yourcompany/work-repo.gitStep 6: Set Your Git Identity Per Project β
bash
# In personal repo
git config user.name "Your Personal Name"
git config user.email "your_personal_email@example.com"
# In work repo
git config user.name "Your Work Name"
git config user.email "your_work_email@company.com"Each repo remembers its own identity. Like spies with different passports.
Optional: Quick Identity Switch Script β
Create git-identity.sh:
bash
#!/bin/bash
if [ "$1" == "personal" ]; then
git config user.name "Your Personal Name"
git config user.email "your_personal_email@example.com"
elif [ "$1" == "work" ]; then
git config user.name "Your Work Name"
git config user.email "your_work_email@company.com"
else
echo "Usage: ./git-identity.sh [personal|work]"
fiMake it executable:
bash
chmod +x git-identity.shπ Mission Complete β
You've just:
- Created two SSH identities
- Configured Git to handle both
- Separated personal from professional, clean and sharp
Welcome to the dual-life, Git Ninja π₯·
Bonus Tip: Check Identity in a Repo β
bash
git config user.name
git config user.emailNow go forth and code β both lives intact.