Skip to content
$ gitswitch
Nord
★ star

Shell Integration

One command sets up three features at once:

Terminal window
gitswitch install
  1. Prompt segment — shows your active git identity in your shell prompt
  2. Identity nudge — suggests the right identity when you cd into a repo
  3. Tab completion — completes gitswitch commands and profile names
Terminal window
gitswitch install

Detects your shell automatically and configures:

ShellConfiguration
StarshipAdds [custom.gitswitch] block to ~/.config/starship.toml
oh-my-zshCreates plugin at ~/.oh-my-zsh/custom/plugins/gitswitch/
Powerlevel10kPrints manual step for ~/.p10k.zsh
Raw zsh/bash/fishAppends directly to rc file

After running gitswitch install:

Terminal window
source ~/.zshrc # zsh
source ~/.bashrc # bash
source ~/.config/fish/config.fish # fish

Or simply open a new terminal.

Shows your active git identity in your shell prompt.

Before:

~/my-project $

After (with gitswitch):

~/my-project [work: alice@company.com] $

The segment only appears when you’re inside a git repo.

The prompt shows:

  • Profile nickname (e.g., work)
  • Email address (e.g., alice@company.com)

Edit ~/.config/starship.toml:

[custom.gitswitch]
command = "gitswitch current --short"
when = "git rev-parse --git-dir 2>/dev/null"
symbol = "🔑 "
format = "[$symbol$output]($style) "
style = "bold 208" # Orange

Change the symbol, color, or format as desired.

Edit ~/.oh-my-zsh/custom/plugins/gitswitch/gitswitch.plugin.zsh:

Terminal window
# Customize the prompt function
GITSWITCH_PROMPT_SYMBOL="🔑 "
GITSWITCH_PROMPT_COLOR="%F{208}"

Edit your rc file directly:

Terminal window
# In ~/.zshrc or ~/.bashrc
PROMPT='%F{208}[$(gitswitch current)]%f $ ' # Zsh
PS1='\[$(gitswitch current)\] $ ' # Bash

When you cd into a repo, gitswitch suggests the identity you usually use there.

Terminal window
$ cd ~/work-project
gitswitch: this repo usually uses work <alice@company.com> switch? [y/N]

Press y to switch, or just hit enter to skip. Non-blocking.

Nudges appear after you’ve used an identity in a repo:

  • ≥3 times with ≥60% consistency

gitswitch records each cd into a repo and remembers which identity was active.

If you find nudges annoying:

Terminal window
# Edit ~/.config/gitswitch/config.json
{
"nudge_on_cd": false
}

Or disable per-shell:

oh-my-zsh:

Terminal window
# Comment out or remove the nudge call in the plugin

Starship:

Terminal window
# Remove the nudge hook from starship.toml

Completes gitswitch commands and profile names.

Terminal window
$ gitswitch <TAB>
add current help install list pin remove switch version
$ gitswitch w<TAB>
work # (if you have a 'work' profile)
  • zsh — automatic if installed
  • bash — automatic if installed
  • fish — automatic if installed

Check:

  1. Is gitswitch install complete?
  2. Did you reload your shell?
  3. Are you in a git repo?
Terminal window
# Test manually
gitswitch current
# Should show your active profile

Check:

  1. Is shell integration installed? (gitswitch install)
  2. Are you in a git repo?
  3. Have you used an identity in this repo ≥3 times?
Terminal window
# Check history
cat ~/.config/gitswitch/history.json

Starship might not have loaded the config. Reload:

Terminal window
# Force starship to reload
pkill starship
# Or restart your terminal

Ensure you’re using a supported shell version:

Terminal window
bash --version # Bash 4+
zsh --version # Zsh 5+
fish --version # Fish 3+

If upgrading doesn’t help, reinstall:

Terminal window
gitswitch install
source ~/.zshrc # or .bashrc

You can write your own prompt function:

Terminal window
# In ~/.zshrc
gitswitch_prompt() {
local current=$(gitswitch current)
if [ -n "$current" ]; then
echo "[$current]"
fi
}
PROMPT='$(gitswitch_prompt) $ '

Only nudge in certain directories:

Terminal window
# In shell plugin
if [[ $PWD == *"work"* ]]; then
gitswitch nudge # (if this command existed)
fi

Quick Start
Real-world Scenarios
CLI Reference