Skip to content

🔐 A small CLI app that allows you to easily add multiple Git accounts on one machine. It switches between accounts automatically based on the workspace you are in.

License

Notifications You must be signed in to change notification settings

savaryna/git-add-account

Repository files navigation

@savaryna/add-git-account

🔐 A small CLI app that allows you to easily add multiple Git accounts on one machine. It switches between accounts automatically based on the workspace you are in.

CLI usage

Run the command direcly with

npx @savaryna/git-add-account

or if you installed it globally with

npm i -g @savaryna/git-add-account

then you can run it using

git-add-account
# or the shorter version
gaa

For usage and command details run it with the --help option.

After going through all the steps, you will be presented with your public SSH key so you can copy, and add it to your Git provider. For example GitHub1:

  1. Copy the public SSH key.
  2. Go to the SSH keys settings page.
  3. Click on New SSH key.
  4. Add the key as an Authentication Key.
  5. Click on Add SSH key.
  6. Add the same key again as a Signing Key if you chose to sign your work2.

Done! Any git command you run from the workspace you chose (and its subdirectories), will now use this new account automatically.

How it works

A simple way to use multiple Git accounts on one machine is to use different SSH configs based on the directory you are in. The way @savaryna/add-git-account works is, it asks you for some basic information and then it creates files under .config/ in the workspace directory you specified.

  1. It creates a private/public ed25519 SSH keypair using ssh-keygen (see code).
  2. It creates a sshconfig file based on this template.
  3. It creates a gitconfig file based on this template.
  4. It appends a conditional include to your global Git config based on this template. This makes sure that any git command you run from the workspace you chose (and its subdirectories), will now use this new account automatically3.
  5. Finally, it presents you with your public SSH key so you can copy, and add it to your Git provider.

License

MIT © Alex Tofan

Footnotes

  1. https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account?tool=webui

  2. https://docs.github.com/en/authentication/managing-commit-signature-verification

  3. https://git-scm.com/docs/git-config#_conditional_includes

About

🔐 A small CLI app that allows you to easily add multiple Git accounts on one machine. It switches between accounts automatically based on the workspace you are in.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •