tips and tricks · · 4 min read

Managing Multiple GitHub Accounts: Personal & Work

How to configure Git for multiple GitHub accounts using per-project remote URLs with Personal Access Tokens. No more credential conflicts.

Using one machine for both personal projects and work? You’ve probably run into the annoying issue where Git pushes with the wrong account. The solution is simple: configure your remotes per-project using Personal Access Tokens.


The Problem

You have:

  • A personal GitHub account (personal-username)
  • A work GitHub account (work-username)

By default, Git uses your global credentials. This causes problems:

  • Commits show up under the wrong identity
  • Push/pull fails because of credential mismatch
  • Work repos accidentally use your personal account

The Solution: Per-Project Remote URLs

Instead of relying on global credentials, embed authentication directly in the remote URL for each project.

Format

https://USERNAME:PERSONAL_ACCESS_TOKEN@github.com/owner/repo.git

This approach is:

  • ✅ Project-specific (no global conflicts)
  • ✅ Works with HTTPS (no SSH key juggling)
  • ✅ Easy to set up and understand

Step 1: Create a Personal Access Token (PAT)

GitHub no longer accepts passwords for Git operations. You need a PAT.

  1. Go to GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)
  2. Click Generate new token (classic)
  3. Give it a name (e.g., “Work Laptop” or “Personal Projects”)
  4. Select scopes:
    • repo — Full control of private repositories
    • workflow — (optional) If you work with GitHub Actions
  5. Click Generate token
  6. Copy the token immediately — you won’t see it again

⚠️ Treat your PAT like a password. Don’t commit it to repos or share it.


Step 2: Configure Remote URL

Navigate to your project and set the remote URL:

For Personal Projects

git remote set-url origin https://personal-username:ghp_xxxxxxxxxxxx@github.com/personal-username/my-project.git

For Work Projects

git remote set-url origin https://work-username:ghp_yyyyyyyyyyyy@github.com/company/work-project.git

Verify the change:

git remote -v

Output:

origin  https://work-username:ghp_yyyyyyyyyyyy@github.com/company/work-project.git (fetch)
origin  https://work-username:ghp_yyyyyyyyyyyy@github.com/company/work-project.git (push)

Step 3: Configure Local Git Identity

Set your name and email per-project to match the GitHub account:

For Personal Projects

git config user.name "Your Name"
git config user.email "personal@email.com"

For Work Projects

git config user.name "Your Name"
git config user.email "work@company.com"

💡 Without the --global flag, these settings only apply to the current repository.

Verify:

git config user.name
git config user.email

Full Workflow Example

Setting up a new work project:

# Clone using the authenticated URL
git clone https://work-username:ghp_yyyyyyyyyyyy@github.com/company/project.git

cd project

# Set local identity
git config user.name "Your Name"
git config user.email "work@company.com"

# Verify
git remote -v
git config user.email

For an existing repo, just update the remote:

cd existing-project
git remote set-url origin https://work-username:ghp_yyyyyyyyyyyy@github.com/company/project.git
git config user.email "work@company.com"

Pro Tips 🔥

1. Check Current Config Before Committing

git config user.email

Make sure it shows the correct email for the repo you’re in.

2. List All Local Configs

git config --list --local

3. Use a Script for New Projects

Create a helper script ~/.local/bin/git-work-setup:

#!/bin/bash
git config user.name "Your Name"
git config user.email "work@company.com"
echo "✅ Work identity configured"

Then run git-work-setup in any work repo.

4. Don’t Commit Your Token

If you accidentally commit a URL with your token:

  1. Revoke the token immediately on GitHub
  2. Generate a new one
  3. Update your remotes

Security Notes

  • PATs have expiration dates — set reminders to regenerate them
  • Use fine-grained tokens when possible for better security
  • Never share tokens in chat, email, or code
  • Revoke unused tokens regularly

When to Use This Approach

Good for:

  • Managing 2-3 accounts on one machine
  • Quick per-project setup
  • HTTPS preference (corporate firewalls often block SSH)

Consider SSH keys if:

  • You have many repos and don’t want to update URLs individually
  • You prefer not to embed tokens in URLs
  • Your workflow involves frequent cloning

Quick Reference

TaskCommand
Set remote URLgit remote set-url origin https://USER:TOKEN@github.com/owner/repo.git
Set local namegit config user.name "Name"
Set local emailgit config user.email "email@example.com"
View remotegit remote -v
View local configgit config --list --local

That’s it. No more “wrong account” commits or failed pushes. Each project knows exactly which identity to use. ✨