@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.
- package/README.md +64 -56
- package/index.js +1 -0
- 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
|
|
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
|
-
|
|
18
|
-
git-add-account
|
|
19
|
+
then you can run it using
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
```shell
|
|
22
|
+
git-add-account
|
|
22
23
|
```
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
or
|
|
25
26
|
|
|
26
27
|
```shell
|
|
27
|
-
|
|
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
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@savaryna/git-add-account",
|
|
3
|
-
"version": "2.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": [
|