A stupidly simple CLI tool to manage multiple Git accounts on single machine.
Clone, commit and push to personal and work repos with different accounts. Set-and-forget, no faff.
- β No more pushing commits under the wrong account
- β No manual SSH or Git config
- β No hacky Git clone URLs
With GitPersona, you'll set up a directory (folder) for each of your Git accounts (GitHub, GitLab, etc.). Each directory will contain the Git repos for each account. For example, your file structure might look like the following:
code/
βββ work/
β βββ important-work-repo
β βββ ...
βββ personal/
βββ my-todolist-app
βββ ...
Once set up, you're winning:
- future Git commits will be authored by the Git account for the parent directory
- pushes will use its SSH key
And when you clone new repositories into the parent directory, it'll all Just Work :)
See how it actually works under the hood.
curl -fsSL https://raw.githubusercontent.com/tomquirk/gitpersona/main/scripts/install.sh | shInstall a specific release:
curl -fsSL https://raw.githubusercontent.com/tomquirk/gitpersona/main/scripts/install.sh | GITP_VERSION=v0.1.0 shRelease assets are also available at github.com/tomquirk/gitpersona/releases.
Creates a new GitPersona profile.
Interactive mode starts when:
- no flags are provided, or
- any required flag is missing (
--name,--email,--codepath).
gitp new --name aeolian --email "email" --codepath "~/code/<name>" --sshkey "~/.ssh/key" --githost "github.com"
# generate a new key with default enctype (ed25519)
gitp new --name aeolian --email "email" --codepath "~/code/<name>"
# generate a new key with enctype override
gitp new --name aeolian --email "email" --codepath "~/code/<name>" --enctype rsaIf no SSH key is provided, one will be created with the name <name>_<enc-type>. ed25519 is the default encryption type. If --enctype is provided and --sshkey is not, that --enctype value is used for key generation.
Removes a GitPersona profile.
Note: your SSH key will not be removed unless
--delete-ssh-keyis provided.
gitp remove <name>
gitp remove <name> --delete-ssh-keyUpdates a GitPersona profile.
gitp update <name> --name aeolian --email "email" --codepath "~/code/<name>" --sshkey "~/.ssh/key" --githost "github.com"Lists all GitPersona profiles.
gitp listSyncs the .ssh/config and .gitconfig files with the GitPersona config file in ~/.config/gitpersona/config.json.
gitp fix GitPersona persists profile data in:
~/.config/gitpersona/config.json
Then it reconciles managed sections inside:
~/.ssh/config~/.gitconfig
For each profile, GitPersona writes the following files:
-
A per-profile SSH config file at
~/.ssh/config-<name>:Host <name> HostName <githost> IdentityFile <ssh key path> User git IdentitiesOnly yes -
A per-profile Git config file at
~/.gitconfig-<name>:[user] name = <name> email = <email> [core] sshCommand = ssh -i <ssh key path> -
Managed include blocks in global files:
In
~/.ssh/config:# >>> gitpersona managed ssh >>> Include ~/.ssh/config-<name> # <<< gitpersona managed ssh <<<In
~/.gitconfig:# >>> gitpersona managed git >>> [includeIf "gitdir:<codepath>/"] path = ~/.gitconfig-<name> # <<< gitpersona managed git <<<
gitp fix rewrites those managed blocks from config.json, removes stale managed entries/files, and preserves unmanaged user content.
You can totally do all this by-hand if you'd like; GitPersona is just a cheat code.
To run the tests:
go test ./...To run the linter:
go vet ./...To run the formatter:
go fmt ./...To test the CLI:
go run ./cmd --helpPushing a v* tag will build and publish archives for Linux/macOS (amd64, arm64) to GitHub Releases.
git tag v0.1.0
git push origin v0.1.0