@savaryna/git-add-account 0.0.1-beta.3 → 1.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.
package/README.md CHANGED
@@ -1,45 +1,85 @@
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.
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.
4
4
 
5
5
  ## Usage
6
6
 
7
- Run the command
7
+ Run the command direcly:
8
8
  ```shell
9
9
  npx @savaryna/git-add-account
10
10
  ```
11
11
 
12
- After going through all the steps
12
+ or if you want to install it globally:
13
+
14
+ ```shell
15
+ npm i -g @savaryna/git-add-account
16
+
17
+ # now you can run it by invoking
18
+ git-add-account
19
+
20
+ # or
21
+ gaa
22
+ ```
23
+
24
+ After going through all the steps:
13
25
 
14
26
  ```shell
15
- Need to install the following packages:
16
- @savaryna/git-add-account
17
- Ok to proceed? (y)
18
27
  ✔ Name to use for this account: … Example Name
19
28
  ✔ Email to use for this account: … example@email.com
20
29
  ✔ Workspace to use for this account: … /Users/savaryna/code/email
21
30
  ✔ Name to use for SSH keys: … email_example_name
22
31
  Enter passphrase (empty for no passphrase):
23
32
  Enter same passphrase again:
24
- Enable signed commits for this account? … no / yes
33
+ Do you want to sign your work? … no / yes
25
34
 
26
- Your public SSH key is: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGme0weZc05wJiXUBmg4Tk0Ox1rhZP6utY48GQTJheGo example@email.com
35
+ Your public SSH key is: ssh-ed25519 AAAAC3NlZ...DITJheGo example@email.com
27
36
  You can also find it here: /Users/savaryna/.ssh/git_email_example_name.pub
28
37
  Add it to your favorite GIT provider and enjoy!
29
38
 
30
- ✨ Done. Thanks for using git-add-account!
39
+ ✨ Done. Thanks for using @savaryna/git-add-account!
31
40
  ```
32
41
 
33
- Your public SSH key will automatically be added to your clipboard so you can add it to your GIT provider. For example GitHub:
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]:
34
43
 
35
- 1. Go to your account [settings/keys](https://github.com/settings/keys)
44
+ 1. Go to your account [settings / keys](https://github.com/settings/keys)
36
45
  2. Click on `New SSH key`
37
- 3. Give it a title
38
- 4. Paste in the public SSH key
39
- 5. Repeat steps 2 - 4 to add a `Signing Key` if you chose to have signed commits
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]
40
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
41
51
  commands issued from this and children directories will automatically use the correct account.
42
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
+
79
+
43
80
  ## License
44
81
 
45
- MIT See [LICENSE](LICENSE) file.
82
+ [MIT](LICENSE) © [Alex Tofan](https://github.com/savaryna)
83
+
84
+ [^1]: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account?tool=webui
85
+ [^2]: https://docs.github.com/en/authentication/managing-commit-signature-verification
@@ -2,7 +2,7 @@ const prompts = require('prompts');
2
2
 
3
3
  const exit = (code = 0, reason = null) => {
4
4
  console.log(reason ? `\n${reason}\n` : '');
5
- console.log(`${code ? '😵 Exited.' : '✨ Done.'} Thanks for using git-add-account!\n`);
5
+ console.log(`${code ? '😵 Exited.' : '✨ Done.'} Thanks for using @savaryna/git-add-account!\n`);
6
6
  process.exit(code);
7
7
  };
8
8
 
package/index.js CHANGED
@@ -117,19 +117,21 @@ async function main() {
117
117
  // Set default ssh command
118
118
  await exec(`git config --file ${workspaceGitConfigPath} core.sshCommand "ssh -i ${sshKeyPath}"`);
119
119
 
120
- const { enableSignedCommits } = await prompts({
120
+ const { signYourWork } = await prompts({
121
121
  type: 'toggle',
122
- name: 'enableSignedCommits',
123
- message: 'Enable signed commits for this account?',
122
+ name: 'signYourWork',
123
+ message: 'Do you want to sign your work?',
124
124
  initial: true,
125
125
  active: 'yes',
126
126
  inactive: 'no',
127
127
  });
128
128
 
129
- // Enable signed commits
130
- if (enableSignedCommits) {
129
+ // Enable signing
130
+ if (signYourWork) {
131
131
  await exec(`git config --file ${workspaceGitConfigPath} gpg.format ssh`);
132
132
  await exec(`git config --file ${workspaceGitConfigPath} commit.gpgsign true`);
133
+ await exec(`git config --file ${workspaceGitConfigPath} push.gpgsign if-asked`);
134
+ await exec(`git config --file ${workspaceGitConfigPath} tag.gpgsign true`);
133
135
  await exec(`git config --file ${workspaceGitConfigPath} user.signingkey ${sshKeyPath}`);
134
136
  }
135
137
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@savaryna/git-add-account",
3
- "version": "0.0.1-beta.3",
4
- "description": "🔐 A small CLI app that allows you to easily add multiple GIT accounts on one machine. It switches between accounts automatically.",
3
+ "version": "1.0.1",
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": [
7
7
  "add",