Metadata-Version: 2.5
Name: git-whoami
Version: 0.1.4
Summary: See which GitHub account each repo commits as and pushes to — and stop the two from drifting apart
Project-URL: Homepage, https://pypi.org/project/git-whoami/
Author: Prapatsorn Sangrod
License: MIT
License-File: LICENSE
Keywords: git,github,identity,multiple-accounts,pre-push,ssh
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Natural Language :: Thai
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Version Control :: Git
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# git-whoami

See which GitHub account each repository **commits as** and **pushes to**,
and stop the two from drifting apart.

ดูว่า git repo แต่ละตัว **commit เป็นใคร** และ **push เข้าบัญชี GitHub ไหน**
แล้วกันไม่ให้สองอย่างนั้นไม่ตรงกัน

```bash
pipx install git-whoami
git whoami          # status of the repo you are in
git whoami ui       # web UI for managing every repo at once
```

Pure standard library. No dependencies. Same behaviour on macOS, Windows and Linux.

## Install

```bash
pipx install git-whoami     # or: pip install --user git-whoami
```

**Then restart your terminal.** `pipx` installs into `~/.local/bin`, and if that
directory is not on your `PATH` yet, nothing you just installed is visible to
the shell you are already in.

If `git whoami` prints

```
git: 'whoami' is not a git command. See 'git --help'.
```

then `PATH` is the problem, not the install. Fix it:

```bash
pipx ensurepath
exec $SHELL          # or just open a new terminal
```

If `pipx ensurepath` reports that the directory is already on `PATH` but the
command still is not found, add it by hand:

| shell | file | line to append |
|---|---|---|
| zsh (macOS default) | `~/.zshrc` | `export PATH="$HOME/.local/bin:$PATH"` |
| bash | `~/.bashrc` | `export PATH="$HOME/.local/bin:$PATH"` |
| fish | `~/.config/fish/config.fish` | `fish_add_path ~/.local/bin` |

On Windows, `pipx` installs into `%USERPROFILE%\.local\bin`. Run
`pipx ensurepath`, then **close and reopen** PowerShell — an open window keeps
the old `PATH`.

To check where it landed:

```bash
pipx list                # what pipx installed, and where
command -v git-whoami    # the path the shell resolves, if any
```

### Why `git whoami` works at all

The executable is named `git-whoami`. Git looks for `git-<something>` on your
`PATH` when it does not recognise a subcommand, so `git whoami` and
`git-whoami` are the same program. Nothing needs to be registered with git.

One consequence: `git whoami --help` is intercepted by git itself, which goes
looking for a man page that does not exist and exits 1. Use `git whoami help`
or `git-whoami --help`.

## Upgrade / uninstall

```bash
pipx upgrade git-whoami
pipx uninstall git-whoami
```

Uninstalling leaves `~/.gitwho.json`, your SSH keys and the `Host gh-*` blocks
in `~/.ssh/config` alone — remove those by hand if you want them gone.

## Why this exists

Two different things get confused all the time:

| | what it is | where it lives |
|---|---|---|
| commit identity | the name in the history | `user.email`, per repo |
| push credential | who GitHub thinks you are | the remote URL |

They can disagree. You commit under your work address, push to your personal
account, GitHub accepts it, and the commits are never attributed to you.

## Not an account switcher

Switching is global state. Forget to switch once and the push goes to the wrong
account. Instead, let the remote URL carry the account:

```
git@gh-work:you/repo.git       → work key
git@gh-personal:you/repo.git   → personal key
```

Each repo is then fixed. Nothing to remember. This tool's job is to **check**
that the commit identity matches the account the remote authenticates as —
and to refuse a push when it does not.

## Adding a second account

```
git whoami ui
```

Fill in the short name and the GitHub username. For the commit address you
have two choices:

- **Type an email.** It appears verbatim in `Author: name <email>`, which reads
  better, but it is public in every commit you push.
- **Leave the email blank and give the user id** (from
  `api.github.com/users/<username>`, field `id`). GitWho builds
  `<id>+<username>@users.noreply.github.com`, which keeps your address private.

Either way the address has to be verified on that GitHub account, or the commits
will not be attributed to you.

GitWho then generates an SSH key for the account and adds a matching
`Host gh-<name>` block to `~/.ssh/config`.

The key still has to reach GitHub. Two ways:

**With the GitHub CLI** — press **Link to GitHub** and the key is uploaded for
you. `gh` must be signed in as that same account, and its token needs the
`admin:public_key` scope:

```bash
gh auth login                                          # sign in as that account
gh auth switch --user <username>                       # if you have several
gh auth refresh -h github.com -s admin:public_key      # one-off, lets gh add keys
```

**By hand** — press **Show public key**, copy the line, and paste it at
`github.com/settings/keys` while signed in as that account.

Either way, press **Test connection** afterwards. It runs `ssh -T` and reports
which user GitHub thinks the key belongs to, so a key pasted into the wrong
account is caught immediately.

Once it passes, press **Use \<name\>** on a repo to bind it.

## Removing an account

**Remove** takes the account out of `~/.gitwho.json` and deletes its `Host`
block from `~/.ssh/config`. The key file stays on disk and repos already bound
to it are left alone — point them somewhere else first if you still need them
to push.

## Commands

```
git whoami                status of the current repo
git whoami ui             web UI: every repo, every account
git whoami accounts       list configured accounts
git whoami use <name>     bind this repo to an account
git whoami guard          install a pre-push hook that blocks mismatches
git whoami lang th|en     switch language (UI and hook follow)
```

## The web UI

`git whoami ui` serves a page from your own machine on `127.0.0.1` and opens it.
Every request needs a token that is generated fresh each launch, so other pages
in your browser cannot drive it. Close the program and the token is dead.

It is a local program with a browser for a front end — nothing is uploaded, and
there is no server to deploy.

## What it touches

- `~/.gitwho.json` — your accounts and language choice
- `~/.ssh/config` — appends `Host gh-*` blocks; existing entries are untouched
- `~/.ssh/id_ed25519_<name>` — one key per account
- a repo's `.git/config` — `user.name`, `user.email`, `remote.origin.url`
- `.git/hooks/pre-push` — only in repos where you turn the guard on

It does not change your global git config and does not touch credentials in
your keychain.

## License

MIT
