@savaryna/git-add-account
v2.2.3
Published
π 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.
Maintainers
Readme
@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.
Agent usage (skill)
Add the skill using
npx skills add savaryna/git-add-accountand ask your agent to "add a new git account".
CLI usage
Run the command direcly with
npx @savaryna/git-add-accountor if you installed it globally with
npm i -g @savaryna/git-add-accountthen you can run it using
git-add-account
# or the shorter version
gaaFor 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 GitHub^1:
- Copy the public SSH key.
- Go to the SSH keys settings page.
- Click on
New SSH key. - Add the key as an
Authentication Key. - Click on
Add SSH key. - Add the same key again as a
Signing Keyif you chose to sign your work^2.
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.
- It creates a private/public
ed25519SSH keypair usingssh-keygen(see code). - It creates a
sshconfigfile based on this template. - It creates a
gitconfigfile based on this template. - It appends a conditional include to your global Git config based on this template. This makes sure that any
gitcommand you run from the workspace you chose (and its subdirectories), will now use this new account automatically^3. - Finally, it presents you with your public SSH key so you can copy, and add it to your Git provider.
License
MIT Β© Alex Tofan
