Never commit with the wrong Git identity again.
Automatically switch Git name, email, and SSH key based on repository location using Git's built-in
includeIffeature.
You have a work GitHub account and a personal GitHub account. You clone repos into different folders. But every now and then, you commit to a personal repo with your work email — or worse, commit to a work repo with your personal email. Now your commit history is wrong, and fixing it means rewriting history.
Managing this manually is error-prone:
git config user.name "Work Name"
git config user.email work@example.com
git config core.sshCommand "ssh -i ~/.ssh/id_ed25519_work"
# ... repeat for every single repogit-persona creates identity profiles and wires them up to folders. Any repo under a profile's folder automatically uses the right name, email, and SSH key. No per-repo config needed.
git persona create work "Work Name" work@example.com ~/dev/work
git persona create personal "Personal Name" personal@example.com ~/dev/personalNow every repo under ~/dev/work/ uses your work identity. Every repo under ~/dev/personal/ uses your personal identity. Done.
- Automatic identity switching using Git's native
includeIf - Automatic SSH key generation per profile
- Per-repository profile overrides
- Current profile detection
- Native Git subcommand (
git persona) - Zero runtime dependencies (pure Bash)
- Linux, macOS, and WSL support
- Requirements
- Compatibility
- Installation
- Quick Start
- Command reference
- How it works
- File locations
- Testing
- Changelog
- Contributing
- License
- Support
- Bash 4.0+
- Git 2.13+ (for
includeIfsupport) - OpenSSH (for
ssh-keygen)
| Platform | Status | Notes |
|---|---|---|
| Linux (Ubuntu, Debian, Fedora, Arch, etc.) | ✅ Fully supported | |
| Alpine Linux | ✅ Fully supported | Pure bash, no GNU sed needed |
| macOS | ✅ Fully supported | Uses built-in bash (or Homebrew bash 5+) |
| Windows (WSL) | ✅ Fully supported | Same as Linux |
| Windows (Git Bash) | Comes with Git for Windows. See note below | |
| Windows (PowerShell/cmd) | ❌ Not supported | Use Git Bash or WSL |
Windows with Git Bash: Expected to work but not yet tested. Git for Windows includes a full bash environment with ssh-keygen and all required tools. There may be a path format mismatch between Git Bash's MSYS-style paths (/c/Users/...) and what Git's includeIf expects on Windows. Install via the one-liner from a Git Bash terminal. If you test it, please open an issue with your results.
curl -fsSL https://raw.githubusercontent.com/balaianu/git-persona/main/install.sh | bashDownloads the script and installs it to ~/.local/bin/git-persona. No cloning required.
git clone https://github.com/balaianu/git-persona.git
cd git-persona
make installThis installs git-persona to ~/.local/bin/ by default. Make sure that directory is in your PATH:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrcmake install PREFIX=/usr/localcd git-persona
git pull
make updatecd git-persona
make uninstallThis removes the script from ~/.local/bin/. Profile data in ~/.config/git-persona/ is not removed. To remove all profile data:
rm -rf ~/.config/git-personaCreate two identities:
git persona create work "Work Name" work@example.com ~/dev/work
git persona create personal "Personal Name" personal@example.com ~/dev/personalAdd the printed SSH public keys to the corresponding GitHub accounts, then clone repos into the matching folders. Every repo under ~/dev/work/ automatically uses your work identity; every repo under ~/dev/personal/ uses your personal one.
Verify the active profile:
git persona currentList configured profiles:
git persona listApply a profile manually to the current repository:
git persona use workSee the Command reference below for all commands and flags.
Since the script is named git-persona, Git automatically recognizes it as a subcommand. Both forms work identically:
git persona create work "Name" work@example.com ~/dev/work # recommended
git-persona create work "Name" work@example.com ~/dev/work # also worksgit persona create work "Work Name" work@example.com ~/dev/workThis will:
- Generate an SSH key at
~/.ssh/id_ed25519_git_work - Create a profile config at
~/.config/git-persona/profiles/work.gitconfig - Add an
includeIfrule to~/.gitconfigfor~/dev/work/ - Print the public key for you to add to GitHub
Add the printed public key to your GitHub account under Settings > SSH and GPG keys.
To skip SSH key generation (e.g. if you already have a key or use HTTPS):
git persona create work "Work Name" work@example.com ~/dev/work --no-ssh-keyThe profile will only set user.name and user.email, without core.sshCommand.
git persona listProfiles:
work
name: Work Name
email: work@example.com
base_dir: /home/andy/dev/work
key: /home/andy/.ssh/id_ed25519_git_work
personal
name: Personal Name
email: personal@example.com
base_dir: /home/andy/dev/personal
key: /home/andy/.ssh/id_ed25519_git_personal
cd ~/some-repo
git persona use workgit persona use-folder work ~/projects/client-aAny git repo under ~/projects/client-a/ will automatically use the work profile.
git persona currentCurrent profile: work
name: Work Name
email: work@example.com
key: /home/andy/.ssh/id_ed25519_git_work
git persona delete workThis removes the profile config and includeIf entries. By default, the SSH key is kept — deleting it could break access to remote repos if the key is in use. The base directory is not removed.
To also remove the SSH key pair:
git persona delete work --with-keysgit persona versiongit-persona uses Git's built-in includeIf directive to apply different configs based on directory paths.
When you create a profile, it generates:
~/.config/git-persona/
profiles/
work.conf # profile metadata (key=value)
work.gitconfig # profile-specific git config
personal.conf # profile metadata (key=value)
personal.gitconfig # profile-specific git config
And adds to ~/.gitconfig:
[includeIf "gitdir:/home/andy/dev/work/"]
path = /home/andy/.config/git-persona/profiles/work.gitconfig
[includeIf "gitdir:/home/andy/dev/personal/"]
path = /home/andy/.config/git-persona/profiles/personal.gitconfigEach profile config sets user.name, user.email, and core.sshCommand:
[user]
name = Work Name
email = work@example.com
[core]
sshCommand = ssh -i /home/andy/.ssh/id_ed25519_git_work -o IdentitiesOnly=yesSo any repo under ~/dev/work/ automatically uses the work identity and SSH key. No per-repo config needed.
| Path | Purpose |
|---|---|
~/.local/bin/git-persona |
The script |
~/.config/git-persona/profiles/<id>.conf |
Per-profile metadata (key=value) |
~/.config/git-persona/profiles/<id>.gitconfig |
Per-profile Git config |
~/.ssh/id_ed25519_git_<id> |
Per-profile SSH key |
~/.gitconfig |
Modified with includeIf entries |
make testOr directly:
bash tests/test_basic.shThe test suite runs in an isolated temp directory and won't touch your real profiles or SSH keys.
See CHANGELOG.md for version history.
See Contributing Guide for development setup, testing, and code style.
Pull requests are welcome. Please ensure tests pass before submitting.
- Usage Guide — detailed command reference
- Configuration — file locations and internals
- Contributing — development setup and guidelines
- Changelog — version history
- Code of Conduct — community standards
MIT — see LICENSE
If you find this tool useful, consider buying me a coffee: