Skip to content

tomquirk/gitpersona

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GitPersona

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

How it works

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.

Getting started

Installation

curl -fsSL https://raw.githubusercontent.com/tomquirk/gitpersona/main/scripts/install.sh | sh

Install a specific release:

curl -fsSL https://raw.githubusercontent.com/tomquirk/gitpersona/main/scripts/install.sh | GITP_VERSION=v0.1.0 sh

Release assets are also available at github.com/tomquirk/gitpersona/releases.

Usage

gitp new

Creates a new GitPersona profile.

Interactive mode starts when:

  • no flags are provided, or
  • any required flag is missing (--name, --email, --codepath).

Example usage

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 rsa

If 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.

gitp remove

Removes a GitPersona profile.

Note: your SSH key will not be removed unless --delete-ssh-key is provided.

gitp remove <name>
gitp remove <name> --delete-ssh-key

gitp update

Updates a GitPersona profile.

gitp update <name> --name aeolian --email "email" --codepath "~/code/<name>" --sshkey "~/.ssh/key" --githost "github.com"

gitp list

Lists all GitPersona profiles.

gitp list

gitp fix

Syncs the .ssh/config and .gitconfig files with the GitPersona config file in ~/.config/gitpersona/config.json.

gitp fix 

How it actually works

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:

  1. A per-profile SSH config file at ~/.ssh/config-<name>:

    Host <name>
        HostName <githost>
        IdentityFile <ssh key path>
        User git
        IdentitiesOnly yes
    
  2. A per-profile Git config file at ~/.gitconfig-<name>:

    [user]
        name = <name>
        email = <email>
    
    [core]
        sshCommand = ssh -i <ssh key path>
    
  3. 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.

Development

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 --help

Releasing binaries to GitHub

Pushing 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

About

🎭 Manage many GitHub accounts on one machine

Resources

Stars

Watchers

Forks

Contributors