@savaryna/git-add-account v2.1.0
@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 (directory/subdirectory) you are in.
Usage
Run the command direcly with
npx @savaryna/git-add-accountor if you want, first install it globally
npm i -g @savaryna/git-add-accountthen you can run it using
git-add-accountor
gaaAfter 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:
- Go to your account settings / keys
- Click on
New SSH key - Give it a title
- Choose
Authentication Keyfor key type - Paste in the public SSH key copied earlier in the key field
- Click on
Add SSH key - Repeat steps 2 through 6 to add a
Signing Keykey type, if you chose to sign your work (Commits, Tags, Pushes)^2 - Done! Now, you can go to the workspace you chose for the account, ex:
cd /Users/john/code/work, and all thegitcommands issued from this, or any other subdirectory, will automatically use the correct account/ssh keys.
Example of 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 some files under .config in the workspace directory you specified. Ex:
- It creates a (private/public) SSH keypair using
ssh-keygen -t ed25519 -C "john@github.com" -f /Users/john/code/work/.config/id_ed25519_git_github_com. See code. It creates a
sshconfigfile. See code.# File at /Users/john/code/work/.config/sshconfig # Config for GIT account john@github.com Host github.com HostName github.com User git AddKeysToAgent yes UseKeychain yes IdentitiesOnly yes IdentityFile /Users/john/code/work/.config/id_ed25519_git_github_comIt creates a
gitconfigfile. See code.# File at /Users/john/code/work/.config/gitconfig # Config for GIT account john@github.com [user] name = John Doe email = john@github.com [core] sshCommand = ssh -F /Users/john/code/work/.config/sshconfig [gpg] format = ssh [commit] gpgsign = true [push] gpgsign = if-asked [tag] gpgsign = true [user] signingkey = /Users/john/code/work/.config/id_ed25519_git_github_comIt runs
git config --global includeIf.gitdir:/Users/john/code/work/.path /Users/john/code/work/.config/gitconfig, this makes sure that as long as you are in the workspace created earlier, or any other subdirectory, git will use the config from step 3 automatically^3. See code.- And finally, it presents you with your public SSH key so you can copy it and add it to your GIT provider of choice.
License
MIT Ā© Alex Tofan
8 months ago
1 year ago
1 year ago
1 year ago
1 year ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago