Skip to content
metruzancaPublic

About

A simple Git Identity manager

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

24 Commits

Folders and files

Repository files navigation

mask

Release Go version Latest release

mask lets you wear a different git identity in each repository. It sets your git user.name/user.email and the SSH key git push uses, so you can commit and push as different people from the same machine without editing config.

Work Sam and personal Sam are two masks. Each carries its own name, email, SSH key, and any extra environment variables you attach to it.

Everything is applied through environment variables. Nothing is written to your git config, and secrets never touch shell history.

By default it is automatic: enter a repository and it puts on the mask you last wore there; leave and it takes the mask off, returning to your default identity.

Installation • Quick start • Automatic mode • Starship prompt • Configuration • Troubleshooting

Entering a repository puts on its mask, leaving takes it off

Features

  • Per-repository memory. A repo remembers the mask you last wore in it, and restores it whenever you cd back in.
  • A codified default. The first run records your git identity as a default profile, so commits outside a mask use values you chose instead of whatever ~/.gitconfig happens to say.
  • Nothing written to git config. Identity and SSH key are exported as environment variables, so a read-only or managed ~/.gitconfig is fine.
  • SSH key per identity. git push uses the key belonging to the mask, not whichever key happens to be first in your agent.
  • GitHub CLI per identity. A mask can name a gh account, so gh pr and friends act as that account without changing the global active one.
  • Extra environment variables. Attach GITHUB_TOKEN, AWS_PROFILE, or anything else to a mask and have it appear and disappear with it.
  • Nested repos and worktrees. The innermost repository wins. Worktrees and submodules of one repository share a single memory entry.
  • No dependencies. One static Go binary, plus a small shell wrapper for fish, bash, or zsh.
  • Interactive when you want it. mask create and mask switch use forms and dropdowns, and every command also works with an explicit name.

Quick start

Install the binary and load the shell wrapper once:

go install github.com/metruzanca/mask@latest

Fish, in ~/.config/fish/config.fish:

mask init fish | source

bash or zsh, in ~/.bashrc or ~/.zshrc:

eval "$(mask init bash)"

Now create your first mask:

$ mask create

The first time it writes config.toml, mask also asks for a default identity, prefilled from your global git config. That identity is used whenever no mask is worn, so commits outside a mask do not silently depend on ~/.gitconfig. In a non-interactive run mask uses the global git identity directly, and skips the default profile when git has none.

The form asks for a name, git name, email, and SSH key. If you do not have a key yet, pick Create a new SSH key and mask runs ssh-keygen for you (Ed25519, optional passphrase). Then pick a repository and choose a mask there:

$ cd ~/dev/work-site
$ mask switch work
mask: wearing "work" in /home/sam/dev/work-site
$ mask
Wearing mask: work
Git identity: Sam Rivera <sam@work.example>
Mode: automatic
Repo: /home/sam/dev/work-site
Remembered here: work

From that point on, entering ~/dev/work-site puts work on automatically:

$ cd ~/dev/work-site
mask: entered /home/sam/dev/work-site -> wearing "work"

$ cd ~/dev/personal-blog
mask: entered /home/sam/dev/personal-blog -> no mask remembered, took off "work" (default identity)

Wear a mask in personal-blog once, and it will be restored on every later visit to that repository.

Check what is available and what is worn:

$ mask list
* work      Sam Rivera <sam@work.example>
  personal  Sam <sam@personal.example>

The mask decides the identity git records, including for a commit that changes nothing:

Two repositories committing as two different people

How it works

mask never edits ~/.gitconfig. When a mask is applied, the shell wrapper sources the output of mask switch, which exports:

  • GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL
  • GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL
  • GIT_SSH_COMMAND (the mask's SSH key, with IdentitiesOnly=yes)
  • GIT_CONFIG_* entries for user.name, user.email, and core.sshCommand
  • MASK_NAME, plus any environment variables defined on the mask

When no mask is worn, the same identity variables are exported from [default], with MASK_NAME left unset and MASK_DEFAULT=1 marking that the default identity is active. The default profile has no ssh_key unless you add one, so pushes keep using your normal SSH setup.

git push therefore uses the key belonging to the mask, not whichever key happens to come first in your agent:

Switching repositories changes the SSH key git uses

Because these are environment variables, they apply to the current shell and everything it starts. A new shell starts clean and syncs itself when the directory hook runs.

Usage

mask create          # form: name, git user.name/email, SSH key (pick or create)
mask switch          # toggle between two masks, dropdown for three or more
mask switch work     # or name one directly
mask                 # what you're wearing now
mask list            # all configured masks
mask off             # take it off, return to the default identity, remember it here
mask on              # put the last mask back on
mask settings        # automatic vs manual control
mask settings off    # same, without the form
mask config          # show all settings
mask config setting.notify false   # silence change notices (creates config if missing)
mask version         # print the version

Switching

  • With two masks, mask switch toggles to the other one.
  • With three or more, it opens a dropdown. Pass a name to skip the dropdown, which also works in scripts and non-interactive terminals.
  • mask switch <name> inside a repository is remembered for that repository when automatic mode is on.
  • A successful switch prints a one-line confirmation naming the mask.

Toggling between two masks and checking what is worn

Turning a mask off, and back on

mask off removes the mask, applies the default identity, and remembers "no mask here" for the current repository, so it stays off. A config without a [default] profile keeps the older behavior of clearing the identity entirely. mask on reverses mask off: it restores the mask remembered for the repository, or the last mask worn in the shell when the repository has no memory. mask off prints a one-line confirmation naming the mask it removed, and stays quiet when no mask is worn.

Starship prompt

Starship can show which mask you are wearing. The shell wrapper exports MASK_NAME in every shell where a mask is on, so a starship custom module can read it directly.

Add this to ~/.config/starship.toml:

[custom.mask]
command = 'printf %s "$MASK_NAME"'
when = 'test -n "$MASK_NAME"'
format = '[🎭 $output](bold purple) '
description = "currently worn mask"

The prompt shows 🎭 work when a mask is worn and nothing when no mask is worn. $all already includes custom modules, so the top-level format needs no change. To place the module in a specific position, reference it by name:

format = "$time${custom.mask}$all"

The command runs in sh, so the same configuration works in fish, bash, and zsh. Starship escapes module output by default, so a mask name cannot inject shell code into your prompt.

The prompt reflects the shell, not repository memory: a new shell picks up the mask for its directory when the wrapper's startup hook runs.

If Starship already tells you which mask is on, the per-change notices printed to stderr become noise. Set notify = false under [settings] in the config file, or run mask config setting.notify false, to silence them; the shell code and repository memory still work as usual.

Automatic mode

When the shell wrapper is loaded, mask reacts to directory changes:

  • Enter a repo you have worn a mask in before and it puts that mask on.
  • Enter a repo with no memory and it returns to the default identity.
  • Leave every repo and it returns to the default identity.
  • Nested repos resolve to the innermost one. Leaving the inner repo restores the outer repo's mask.
  • Worktrees and submodules are tracked by their git directory, so two worktrees of the same repository share one memory entry.
  • A new shell starts on the default identity, and inside a repo it syncs to that repo's mask immediately.

Every automatic change prints a notice naming the mask that went on or off, for example mask: entered ~/dev/foo -> wearing "work" or mask: left repo -> took off "work" (default identity). Set notify = false under [settings] or run mask config setting.notify false to turn these notices off; the mask still changes, it just does so quietly.

Repo memory is written when you run mask switch <name> inside a repository. mask off inside a repository records an explicit "no mask here", so the absence of a mask is also a decision that sticks.

Manual mode

To take control, turn automatic mode off:

mask settings off

Or set automatic = false under [settings] in the config file. The mask then only changes when you run mask switch or mask off, and it lasts for the shell session. A new terminal starts on your default identity. The default is applied even in manual mode because it is the baseline, not a repository change.

Repo memory is not touched while manual, so switch and off change only the current shell. Turning automatic back on picks up wherever the memory was left.

Configuration

The config lives at ~/.config/mask/config.toml (or $XDG_CONFIG_HOME/mask/config.toml). The first command that needs to write it creates it with a default identity, seeded from your global git config; edit the file to add environment variables or fine-tune settings.

[default]
  git_name  = "Sam"
  git_email = "sam@personal.example"

[mask.personal]
  git_name  = "Sam"
  git_email = "sam@personal.example"
  ssh_key   = "~/.ssh/id_ed25519_personal"

[mask.personal.env]
  GITHUB_TOKEN = "ghp_x"

[mask.work]
  git_name  = "Sam Rivera"
  git_email = "sam@work.example"
  ssh_key   = "~/.ssh/id_ed25519_work"

[settings]
automatic = true
notify    = true

The default identity

[default] is used whenever no mask is worn: after mask off, when you leave a repository, and in a new shell. mask asks for it once, prefilled from your global git config. Non-interactive runs seed it from git silently, and skip the profile when git has no identity configured.

Unlike a mask, the generated default has no ssh_key, so pushes keep using your normal SSH agent and config. Add ssh_key to [default] if you want to pin pushes as well. The default profile accepts env and gh_user like any mask.

No mask is still "no mask": MASK_NAME stays unset, mask reports No mask worn (default identity), and the Starship badge stays hidden. MASK_DEFAULT=1 marks that the baseline is applied, so the directory hook does not reapply it on every prompt.

Edit [default] to change the identity commits use outside masks. Delete it to return to the old behavior of falling back to ~/.gitconfig.

Environment variables in a mask's env table are exported with the mask and removed when it goes off:

Per-mask environment variables changing with the directory

GitHub CLI identity

If you use gh and are logged in to more than one account, a mask can carry the GitHub account name instead of a token:

[mask.work]
  git_name  = "Sam Rivera"
  git_email = "sam@work.example"
  ssh_key   = "~/.ssh/id_ed25519_work"
  gh_user   = "work-account"

When the mask is worn, mask asks gh auth token --user work-account for that account's token and exports it as GH_TOKEN. gh gives GH_TOKEN precedence over its stored accounts, so gh pr, gh api, and gh auth status act as that account, while gh's global active account is left alone. Turning the mask off or switching to another mask removes the variable again.

The token is never written to the config file, so it follows whatever is stored in gh's keyring and survives token rotation. Git pushes still use the mask's SSH key; gh_user only changes what the gh CLI does.

gh_user is optional and only useful on GitHub. If gh is missing or no such account is logged in, mask prints a warning and wears the rest of the mask without a token, so a directory change never fails. An explicit GH_TOKEN in [mask.<name>.env] takes precedence over gh_user.

Both settings can also be changed from the CLI with mask config, which creates the config file when it is missing. On a terminal, the first write asks for the default identity before saving:

mask config                          # show every setting
mask config setting.notify           # show one setting
mask config setting.notify false     # change one setting
mask config setting.automatic true

Choosing a default

The generated default follows the git identity you already had, so nothing changes on day one. From there:

  • Edit [default] to choose exactly which identity commits use outside masks, independent of ~/.gitconfig.
  • Delete [default] to fall back to ~/.gitconfig exactly as older versions did.
  • Use masks for everything else. Add a work mask and wear it in work repos; everything else keeps the default.

Automatic mode still applies the mask a repo was last given. A repo with no memory returns to the default identity.

Files

All files live under ~/.config/mask/ (or $XDG_CONFIG_HOME/mask/):

  • config.toml: the default identity, masks, and settings. Hand-edited or managed with mask create, mask config, and mask settings.
  • repos.toml: the repository-to-mask memory used by automatic mode. Kept separate on purpose, so you can commit it to your dotfiles or ignore it independently.
  • auto.log: a bounded log of automatic changes, useful when debugging why a mask was applied.

repos.toml is safe to delete; the memory is rebuilt as you switch masks in repositories. auto.log is safe to delete too.

Installation

With Go

go install github.com/metruzanca/mask@latest

Go 1.26 or later is required.

Prebuilt binaries

Download Linux, macOS, or Windows binaries from the releases page.

From source

git clone https://github.com/metruzanca/mask
cd mask
go install .

Upgrading

After upgrading from an older version, re-run mask init <shell> to install the current directory hook, then restart your shell:

eval "$(mask init bash)"

Troubleshooting

The mask changes when I cd, but not in a new shell

The wrapper runs the hook at startup, so this usually means the wrapper is not loaded. Check that mask init <shell> is evaluated in the right startup file, then restart the shell.

mask switch asks for a terminal

With three or more masks, mask switch needs a dropdown. Pass a name to choose without one:

mask switch work

A repository does not get a mask automatically

Automatic mode may be off, or the repository may have an explicit "no mask" memory. Check with:

mask
mask settings

Then run mask switch <name> inside the repository to remember a mask there.

git push uses the wrong SSH key

Print what is currently exported:

env | grep -E 'GIT_SSH_COMMAND|GIT_CONFIG'

The mask sets GIT_SSH_COMMAND to ssh -i <key> -o IdentitiesOnly=yes. If you override it elsewhere, the mask's value can lose. Also make sure the key exists and is readable.

Nested repositories wear the wrong mask

Nested repos resolve to the innermost repository. A worktree or submodule is identified by its git directory, so all of its worktrees share one memory entry. If that is not what you want, wear the mask you need after entering the inner repository.

Development

git clone https://github.com/metruzanca/mask
cd mask

# Build
go build

# Run tests
go test ./...

# Install the working copy
go install .

The README GIFs are recorded from VHS tapes in docs/vhs; see docs/vhs/README.md to regenerate them.

Releases are built by GoReleaser for Linux, macOS, and Windows on amd64 and arm64. Tag a commit with vMAJOR.MINOR.PATCH to publish one.

About

A simple Git Identity manager

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Contributors

Languages