Identity Awareness
What it does
Section titled “What it does”gitswitch learns which identity you use in each repository. When you switch to a repo, it nudges you if the current identity looks wrong.
cd ~/work-projectgitswitch: this repo usually uses work <alice@company.com> — switch? [y/N]Why you need this
Section titled “Why you need this”Identity mistakes are easy to make:
- You forget to switch before committing
- You work on many repos and lose track of which identity each uses
- You only realize the mistake after pushing
Identity awareness prevents these mistakes by:
- Remembering which identity you use in each repo
- Suggesting (or auto-switching to) the right identity
- Making it a one-keypress fix
How it works
Section titled “How it works”Learning phase
Section titled “Learning phase”Each time you enter a git repo, gitswitch checks:
- What identity is currently active?
- Is this a new repo or have I been here before?
- Record this usage in
~/.config/gitswitch/history.json
After using an identity in a repo ≥3 times with ≥60% consistency, gitswitch recognizes the pattern.
Nudging
Section titled “Nudging”Once a pattern is clear, you get a nudge:
gitswitch: this repo usually uses work <alice@company.com> — switch? [y/N]- Press
yto switch - Press
nor just hit enter to skip - Non-blocking — you can proceed either way
This happens automatically when you:
- Open a new terminal in the repo
cdinto the repo (with shell integration installed)
Pinning
Section titled “Pinning”If you always want a specific identity in a repo, pin it:
cd ~/my-work-repogitswitch pin workNow the nudge becomes a permanent rule — you’ll always get the same suggestion, even if you occasionally use a different identity.
Install shell integration
Section titled “Install shell integration”For automatic nudges on cd:
gitswitch installThis detects your shell (Starship, oh-my-zsh, Powerlevel10k, raw zsh/bash/fish) and adds the nudge hook.
View history
Section titled “View history”History is stored at:
~/.config/gitswitch/history.jsonExample entry:
{ "/Users/alice/work-project": { "work": 12, "personal": 2 }}This repo has been accessed 12 times with work identity and 2 times with personal.
Clear history
Section titled “Clear history”To reset learning for a repo:
# Edit the history file manually, orrm ~/.config/gitswitch/history.json# Clears all history (starts learning from scratch)Pinning
Section titled “Pinning”Pin an identity to a repo
Section titled “Pin an identity to a repo”cd ~/my-work-repogitswitch pin workCreates a .gitswitch file in the repo (gitignore it):
echo .gitswitch >> .gitignoreRemove pin
Section titled “Remove pin”gitswitch unpinFalls back to usage-based learning.
Pin with multiple remotes
Section titled “Pin with multiple remotes”If you clone the same repo to different locations, each location learns separately:
# Location 1cd ~/projects/work-projectgitswitch pin work
# Location 2cd ~/backups/work-project-backupgitswitch pin work
# Each maintains its own identity preferenceCustomization
Section titled “Customization”Adjust learning threshold
Section titled “Adjust learning threshold”Currently: ≥3 uses + ≥60% consistency
To change this, edit ~/.config/gitswitch/config.json:
{ "learning": { "min_uses": 3, "confidence_threshold": 0.6 }}Disable nudges
Section titled “Disable nudges”To turn off nudges globally, edit ~/.config/gitswitch/config.json:
{ "nudge_on_cd": false}Clear all learning
Section titled “Clear all learning”rm ~/.config/gitswitch/history.jsonExamples
Section titled “Examples”Multi-repo workflows
Section titled “Multi-repo workflows”Contractor with 3 client repos:
cd ~/clienta-project# First time, no nudge (learning)gitswitch clienta
cd ~/clientb-projectgitswitch clientb
cd ~/clienta-project# gitswitch now suggests clienta (if on 3rd visit)
cd ~/personal-project# gitswitch suggests personalUsing pins
Section titled “Using pins”Some repos you always want pinned:
# Work repos — pin themcd ~/company-repogitswitch pin work
cd ~/api-projectgitswitch pin work
# Personal repos — pin themcd ~/github-clonegitswitch pin personalTroubleshooting
Section titled “Troubleshooting”Nudges not appearing on cd
Section titled “Nudges not appearing on cd”Check:
- Did you run
gitswitch install? - Is your shell supported? (Starship, oh-my-zsh, Powerlevel10k, zsh, bash, fish)
- Did you reload your shell?
gitswitch installsource ~/.zshrc # or open new terminalWrong nudge suggestions
Section titled “Wrong nudge suggestions”The learning threshold might be too low. Check ~/.config/gitswitch/history.json to see usage counts.
If a wrong identity has too many uses, manually edit the history or use:
rm ~/.config/gitswitch/history.jsonThis resets learning for all repos.
Pin file conflicts
Section titled “Pin file conflicts”If .gitswitch file conflicts with something:
# Edit gitswitch config to use a different filename# (not currently supported, would need code change)For now, use the learned nudges instead of pinning.