@anhducmata/git-manager 1.0.0 → 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 +146 -0
- package/index.js +3 -3
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# @anhducmata/git-manager
|
|
2
|
+
|
|
3
|
+
> Instantly switch between multiple Git accounts (SSH keys + user config) on a single machine.
|
|
4
|
+
|
|
5
|
+
If you use **multiple GitHub/GitLab accounts** on one laptop (e.g. Work + Personal), this CLI tool lets you switch between them in seconds — including the SSH key, so `git push` always goes to the right account.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## ✨ Features
|
|
10
|
+
|
|
11
|
+
- **One command to switch** — changes `user.name`, `user.email`, and SSH key all at once
|
|
12
|
+
- **Auto-generates SSH keys** — creates a dedicated `ed25519` key per profile
|
|
13
|
+
- **No more SSH conflicts** — uses `core.sshCommand` with `IdentitiesOnly=yes` so Git always uses the correct key
|
|
14
|
+
- **Interactive prompts** — no flags to memorize, just follow the menu
|
|
15
|
+
- **Lightweight** — zero config files to edit manually
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 📦 Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install -g @anhducmata/git-manager
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
After installing, the `gitm` command is available globally.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 🚀 Quick Start
|
|
30
|
+
|
|
31
|
+
### 1. Add your first account
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
gitm new
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
You'll be asked for:
|
|
38
|
+
- **Profile name** — a label like `Work` or `Personal`
|
|
39
|
+
- **Git user.name** — the name that appears on your commits
|
|
40
|
+
- **Git user.email** — the email tied to your Git provider
|
|
41
|
+
- **SSH key** — press Enter to auto-generate a new `ed25519` key, or provide a path to an existing one
|
|
42
|
+
|
|
43
|
+
After the key is generated, the tool prints your **public key** so you can copy it into GitHub/GitLab:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
ssh-ed25519 AAAAC3Nza... your-email@example.com
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
> 💡 Add this key to your Git provider:
|
|
50
|
+
> - **GitHub**: Settings → SSH and GPG keys → New SSH key
|
|
51
|
+
> - **GitLab**: Preferences → SSH Keys → Add new key
|
|
52
|
+
|
|
53
|
+
### 2. Add your second account
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
gitm new
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Repeat the same process for your other account (e.g. `Personal`).
|
|
60
|
+
|
|
61
|
+
### 3. Switch between accounts
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
gitm switch
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
You'll see:
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
Current active user: John Doe <john@work.com>
|
|
71
|
+
|
|
72
|
+
? Select an account to switch to:
|
|
73
|
+
❯ Work (John Doe <john@work.com>)
|
|
74
|
+
Personal (Johnny <johnny@gmail.com>)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Select the one you want — done! Your Git user **and** SSH key are both switched instantly.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## 📖 Commands
|
|
82
|
+
|
|
83
|
+
| Command | Description |
|
|
84
|
+
|---|---|
|
|
85
|
+
| `gitm new` | Add a new Git account with SSH key |
|
|
86
|
+
| `gitm switch` | Interactively switch between saved accounts |
|
|
87
|
+
| `gitm list` | Show all saved accounts + current active user |
|
|
88
|
+
| `gitm remove` | Remove a saved account (optionally delete its SSH key) |
|
|
89
|
+
| `gitm --help` | Show help |
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 🔧 How It Works
|
|
94
|
+
|
|
95
|
+
When you run `gitm switch`, the tool does three things:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# 1. Set Git identity
|
|
99
|
+
git config --global user.name "Your Name"
|
|
100
|
+
git config --global user.email "your@email.com"
|
|
101
|
+
|
|
102
|
+
# 2. Force Git to use the correct SSH key
|
|
103
|
+
git config --global core.sshCommand "ssh -i ~/.ssh/id_ed25519_gm_work -o IdentitiesOnly=yes"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The `IdentitiesOnly=yes` flag is critical — it tells SSH to **only** use the specified key and ignore any other keys loaded in your SSH agent. This prevents the common problem where `git push` uses the wrong account.
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## 📁 Where Data Is Stored
|
|
111
|
+
|
|
112
|
+
| Path | Contents |
|
|
113
|
+
|---|---|
|
|
114
|
+
| `~/.config/git-manager/accounts.json` | Your saved profiles |
|
|
115
|
+
| `~/.ssh/id_ed25519_gm_<profile>` | Auto-generated SSH private keys |
|
|
116
|
+
| `~/.ssh/id_ed25519_gm_<profile>.pub` | Auto-generated SSH public keys |
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## ❓ FAQ
|
|
121
|
+
|
|
122
|
+
### Can I use an existing SSH key instead of generating a new one?
|
|
123
|
+
|
|
124
|
+
Yes! When `gitm new` asks for the SSH key path, just type the full path to your existing key instead of pressing Enter:
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
? Enter SSH key path: /Users/you/.ssh/id_rsa
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Does this affect per-repo Git config?
|
|
131
|
+
|
|
132
|
+
No. This tool only modifies `--global` Git config. If a repo has its own local `.git/config` with `user.name` / `user.email`, that will still take priority inside that repo.
|
|
133
|
+
|
|
134
|
+
### What if I already have `~/.ssh/config` set up?
|
|
135
|
+
|
|
136
|
+
This tool uses `core.sshCommand` which overrides `~/.ssh/config` for Git operations. Your SSH config still works for non-Git SSH connections (like `ssh myserver`).
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## 🤝 Contributing
|
|
141
|
+
|
|
142
|
+
PRs welcome! Feel free to open issues or submit pull requests.
|
|
143
|
+
|
|
144
|
+
## 📄 License
|
|
145
|
+
|
|
146
|
+
ISC
|
package/index.js
CHANGED
|
@@ -41,7 +41,7 @@ function getCurrentGitUser() {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
program
|
|
44
|
-
.name('
|
|
44
|
+
.name('gitm')
|
|
45
45
|
.description('Git Account Manager CLI')
|
|
46
46
|
.version('1.0.0');
|
|
47
47
|
|
|
@@ -51,7 +51,7 @@ program
|
|
|
51
51
|
.action(() => {
|
|
52
52
|
const accounts = loadAccounts();
|
|
53
53
|
if (accounts.length === 0) {
|
|
54
|
-
console.log(chalk.yellow('No accounts found. Add one with `
|
|
54
|
+
console.log(chalk.yellow('No accounts found. Add one with `gitm new`.'));
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
console.log(chalk.bold('\nAvailable Git Accounts:'));
|
|
@@ -141,7 +141,7 @@ program
|
|
|
141
141
|
.action(async () => {
|
|
142
142
|
const accounts = loadAccounts();
|
|
143
143
|
if (accounts.length === 0) {
|
|
144
|
-
console.log(chalk.yellow('No accounts found. Add one with `
|
|
144
|
+
console.log(chalk.yellow('No accounts found. Add one with `gitm new`.'));
|
|
145
145
|
return;
|
|
146
146
|
}
|
|
147
147
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anhducmata/git-manager",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "CLI to easily manage and switch between multiple Git accounts",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
|
-
"
|
|
8
|
+
"gitm": "index.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|