@savaryna/git-add-account 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +64 -56
  2. package/index.js +1 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,81 +1,88 @@
1
1
  # @savaryna/add-git-account
2
2
 
3
- 🔐 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) you are in.
3
+ 🔐 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.
4
4
 
5
5
  ## Usage
6
6
 
7
- Run the command direcly:
7
+ Run the command direcly with
8
+
8
9
  ```shell
9
10
  npx @savaryna/git-add-account
10
11
  ```
11
12
 
12
- or if you want to install it globally:
13
+ or if you want, first install it globally
13
14
 
14
15
  ```shell
15
16
  npm i -g @savaryna/git-add-account
17
+ ```
16
18
 
17
- # now you can run it by invoking
18
- git-add-account
19
+ then you can run it using
19
20
 
20
- # or
21
- gaa
21
+ ```shell
22
+ git-add-account
22
23
  ```
23
24
 
24
- After going through all the steps:
25
+ or
25
26
 
26
27
  ```shell
27
- ✔ Name to use for this account: … Example Name
28
- ✔ Email to use for this account: … example@email.com
29
- ✔ Workspace to use for this account: … /Users/savaryna/code/email
30
- ✔ Name to use for SSH keys: … email_example_name
31
- Enter passphrase (empty for no passphrase):
32
- Enter same passphrase again:
33
- ✔ Do you want to sign your work? … no / yes
34
-
35
- Your public SSH key is: ssh-ed25519 AAAAC3NlZ...DITJheGo example@email.com
36
- You can also find it here: /Users/savaryna/.ssh/git_email_example_name.pub
37
- Add it to your favorite GIT provider and enjoy!
38
-
39
- ✨ Done. Thanks for using @savaryna/git-add-account!
28
+ gaa
40
29
  ```
41
30
 
42
- You will be presented with your public SSH key so you can copy, and add it to your GIT provider. For example GitHub[^1]:
31
+ 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]:
43
32
 
44
33
  1. Go to your account [settings / keys](https://github.com/settings/keys)
45
- 2. Click on `New SSH key`
46
- 3. Give it any title
47
- 4. Choose `Authentication Key` for key type
48
- 4. Paste in the public SSH key copied earlier in the key field
49
- 5. Repeat steps 2 - 4 to add a `Signing Key` key type, if you chose to sign your work (Commits, Tags, Pushes)[^2]
50
- 6. Done! Now you can go to the workspace you chose for the account `/Users/savaryna/code/email` in this example, and all the GIT
51
- commands issued from this and children directories will automatically use the correct account.
52
-
53
- ## How it works
54
-
55
- A simple way to use multiple git accounts on one machine is to use multiple SSH keys configured with different hosts. The way [@savaryna/add-git-account](https://www.npmjs.com/package/@savaryna/git-add-account) works is, it asks you for some basic information and then:
56
-
57
- 1. It creates a `.gitconfig` file in the workspace directory you specified.
58
- 2. It creates a SSH keypair using `ssh-keygen -t ed25519 -C "email@you.specified" -f ~/.ssh/git_the_ssh_key_name_you_specified`.
59
- 3. It appends to the `~/.ssh/config` file.
60
- ```ini
61
- # Config for GIT account email@you.specified
62
- Host *
63
- AddKeysToAgent yes
64
- UseKeychain yes
65
- IdentityFile path/to/the/SSH/key/created/in/step/2
66
- ```
67
- 4. It runs `git config --file path/to/.gitconfig/from/step/1 user.name "name_you_specified"` to set your git username.
68
- 5. It runs `git config --file path/to/.gitconfig/from/step/1 user.email "email@you.specified"` to set your git email.
69
- 6. It runs `git config --file path/to/.gitconfig/from/step/1 core.sshCommand "ssh -i path/to/the/SSH/key/created/in/step/2"` to make sure all the commands issued from this workspace use the correct SSH key.
70
- 7. If you chose to sign your work:
71
- 1. It runs `git config --file path/to/.gitconfig/from/step/1 gpg.format ssh` to use SSH key for signing.
72
- 2. It runs `git config --file path/to/.gitconfig/from/step/1 commit.gpgsign true` to enable signing commits.
73
- 3. It runs `git config --file path/to/.gitconfig/from/step/1 push.gpgsign if-asked` to enable signing pushes if supported.
74
- 4. It runs `git config --file path/to/.gitconfig/from/step/1 tag.gpgsign true` to enable signing tags.
75
- 5. It runs `git config --file path/to/.gitconfig/from/step/1 user.signingkey path/to/the/SSH/key/created/in/step/2` to set the signing key to the one created in step 2.
76
- 8. It runs `git config --global includeIf.gitdir:path/to/your/workspace/.path $path/to/.gitconfig/from/step/1`, this makes sure that if you are in the workspace for the created account, git will use the config from step 1 with all the options from the step 5, 6 and 7 automatically.
77
- 9. And finally it presents you with your public SSH key so you can copy it and add it to your GIT provider of choice.
78
-
34
+ 1. Click on `New SSH key`
35
+ 1. Give it a title
36
+ 1. Choose `Authentication Key` for key type
37
+ 1. Paste in the public SSH key copied earlier in the key field
38
+ 1. Click on `Add SSH key`
39
+ 1. Repeat steps **2 through 6** to add a `Signing Key` key type, if you chose to sign your work (Commits, Tags, Pushes)[^2]
40
+ 1. Done! Now, you can go to the workspace you chose for the account, ex: `cd /Users/john/code/work`, and all the `git`
41
+ commands issued from this, **or any other subdirectory**, will automatically use the correct account/ssh keys.
42
+
43
+ ## Example of how it works
44
+
45
+ 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](https://www.npmjs.com/package/@savaryna/git-add-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:
46
+
47
+ 1. 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](https://github.com/savaryna/git-add-account/blob/main/index.js#L24-L25).
48
+ 1. It creates a `sshconfig` file. [See code](https://github.com/savaryna/git-add-account/blob/main/index.js#L35-L47).
49
+
50
+ ```ini
51
+ # File at /Users/john/code/work/.config/sshconfig
52
+ # Config for GIT account john@github.com
53
+ Host github.com
54
+ HostName github.com
55
+ User git
56
+ AddKeysToAgent yes
57
+ UseKeychain yes
58
+ IdentitiesOnly yes
59
+ IdentityFile /Users/john/code/work/.config/id_ed25519_git_github_com
60
+ ```
61
+
62
+ 1. It creates a `gitconfig` file. [See code](https://github.com/savaryna/git-add-account/blob/main/index.js#L49-L75).
63
+
64
+ ```ini
65
+ # File at /Users/john/code/work/.config/gitconfig
66
+ # Config for GIT account john@github.com
67
+ [user]
68
+ name = John Doe
69
+ email = john@github.com
70
+ [core]
71
+ sshCommand = ssh -F /Users/john/code/work/.config/sshconfig
72
+ [gpg]
73
+ format = ssh
74
+ [commit]
75
+ gpgsign = true
76
+ [push]
77
+ gpgsign = if-asked
78
+ [tag]
79
+ gpgsign = true
80
+ [user]
81
+ signingkey = /Users/john/code/work/.config/id_ed25519_git_github_com
82
+ ```
83
+
84
+ 1. It 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](https://github.com/savaryna/git-add-account/blob/main/index.js#L77-L78).
85
+ 1. And finally, it presents you with your public SSH key so you can copy it and add it to your GIT provider of choice.
79
86
 
80
87
  ## License
81
88
 
@@ -83,3 +90,4 @@ A simple way to use multiple git accounts on one machine is to use multiple SSH
83
90
 
84
91
  [^1]: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account?tool=webui
85
92
  [^2]: https://docs.github.com/en/authentication/managing-commit-signature-verification
93
+ [^3]: https://git-scm.com/docs/git-config#_conditional_includes
package/index.js CHANGED
@@ -48,6 +48,7 @@ async function main() {
48
48
 
49
49
  // Create gitconfig for the workspace
50
50
  const gitConfig = `
51
+ # Config for GIT account ${email}
51
52
  [user]
52
53
  name = ${name.value}
53
54
  email = ${email}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@savaryna/git-add-account",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "🔐 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) you are in.",
5
5
  "homepage": "https://github.com/savaryna/git-add-account#readme",
6
6
  "keywords": [