f you use your MacBook Pro for both professional work and personal side projects, you’ve likely run into the “identity crisis” of Git. You commit code to a personal repo, only to realize later that it’s signed with your corporate email—or worse, you’re blocked from pushing because of SSH key conflicts.
The most robust solution isn’t manually changing your config every time you switch projects; it’s using Git Conditional Includes.
The Strategy: Folder-Based Identity
We are going to organize your Mac so that Git automatically knows who you are based on which folder you are standing in.
- Work Projects: Located in
~/Documents/work/ - Private Projects: Located in
~/Documents/private/
Step 1: Create Your Private Git Identity
Your main .gitconfig already holds your work details. We need to create a separate “mini” config for your personal life.
- Open your terminal.
- Create the file:
touch ~/.gitconfig-private - Add your personal details:Ini, TOML
[user] name = Your Personal Name email = personal-email@example.com
Step 2: Configure the “Conditional Include”
Now, we tell your global Git configuration to swap identities automatically.
- Open your global config:
nano ~/.gitconfig - Update it to look like this:
Ini, TOML
[user]
name = bsj-hoc-tran
email = hoc.tran@mycompany.com
# The Magic: If the folder path starts with /private/, use the private config
[includeIf "gitdir:~/Documents/private/"]
path = ~/.gitconfig-private
Step 3: Handle SSH Authentication
GitHub identifies your account based on the SSH key you present. You cannot use the same SSH key for two different GitHub accounts.
1. Generate a New SSH Key
Bash
ssh-keygen -t ed25519 -C "personal-email@example.com" -f ~/.ssh/id_ed25519_private
2. Update your SSH Config
Edit (or create) ~/.ssh/config to define “aliases” for GitHub:
Plaintext
# Work Account (Default)
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
# Private Account (Alias)
Host github.com-private
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_private
Step 4: Add the New Key to GitHub
- Copy your new public key:
pbcopy < ~/.ssh/id_ed25519_private.pub - Log into your Private GitHub Account.
- Go to Settings > SSH and GPG keys > New SSH Key and paste it there.
Step 5: Putting it into Practice
The workflow changes slightly when you clone personal repositories. Because we created an alias in the SSH config, you must use it in the URL.
To clone a personal repo:
Bash
# Instead of git@github.com...
git clone git@github.com-private:your-username/your-repo.git
Once cloned into your ~/Documents/private/ folder, Git will automatically use your personal email for all future commits in that directory.
Summary Checklist
| Task | Work Account | Private Account |
| Storage Folder | ~/Documents/work/ | ~/Documents/private/ |
| Config File | ~/.gitconfig | ~/.gitconfig-private |
| SSH Key | id_ed25519_work | id_ed25519_private |
| Clone Host | github.com | github.com-private |
Verification
To ensure everything is working, navigate into a private project folder and run:
git config user.email
If it returns your personal email, you’re all set! No more corporate emails on your weekend hobby projects.