Skip to content

Commit b0591eb

Browse files
committed
docs: content
1 parent 1499798 commit b0591eb

2 files changed

Lines changed: 185 additions & 0 deletions

File tree

article.md

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# Stop Committing with the Wrong Git Identity
2+
3+
We've all done it. You finish a feature, push it, and then realize you just committed to your client's repo as `Jane Doe <jane@personal.com>` instead of `Jane Dev <jane@company.com>`.
4+
5+
Or worse — you opened a PR to an open-source project and your work email is now public forever.
6+
7+
Managing multiple git identities is a solved problem that nobody has solved cleanly. Until now.
8+
9+
---
10+
11+
## The old ways
12+
13+
**Option 1: Edit `~/.gitconfig` before every project**
14+
15+
```bash
16+
git config --global user.email jane@company.com
17+
# ... do some work ...
18+
git config --global user.email jane@personal.com
19+
# ... forget to switch back ...
20+
```
21+
22+
You will forget. Every time.
23+
24+
**Option 2: `includeIf` in `~/.gitconfig`**
25+
26+
```ini
27+
[includeIf "gitdir:~/work/"]
28+
path = ~/.gitconfig-work
29+
[includeIf "gitdir:~/personal/"]
30+
path = ~/.gitconfig-personal
31+
```
32+
33+
Works if every project lives in a tidy folder structure. Mine don't. Yours probably don't either.
34+
35+
**Option 3: Set it per-repo, manually, every time**
36+
37+
```bash
38+
git clone git@github.com:company/project.git
39+
cd project
40+
git config user.name "Jane Dev"
41+
git config user.email "jane@company.com"
42+
# also need to set core.sshCommand if using per-identity SSH keys...
43+
# and user.signingkey if GPG signing...
44+
```
45+
46+
Four commands every single time. That's not a workflow, that's a tax.
47+
48+
---
49+
50+
## A better way: `git-profile`
51+
52+
`git-profile` is a small CLI tool I built in Go that lets you define named identity profiles and apply them to any repo with a single command.
53+
54+
```bash
55+
# One-time setup
56+
git-profile add --id work --name "Jane Dev" --email jane@company.com
57+
git-profile add --id personal --name "Jane Doe" --email jane@example.com \
58+
--ssh-key ~/.ssh/id_ed25519_personal
59+
60+
# Per repo, one command
61+
git-profile use work
62+
```
63+
64+
That's it. It sets `user.name`, `user.email`, `core.sshCommand`, `user.signingkey`, and `commit.gpgsign` all at once, only for that repo.
65+
66+
---
67+
68+
## What it looks like day-to-day
69+
70+
```bash
71+
$ git-profile list
72+
73+
PROFILE USER EMAIL SSH KEY
74+
──────────────────────────────────────────────────────────────
75+
personal Jane Doe jane@example.com ~/.ssh/id_ed25519_personal
76+
● work Jane Dev jane@company.com (default)
77+
78+
$ git-profile current
79+
80+
Current git identity
81+
82+
user.name Jane Dev
83+
user.email jane@company.com
84+
ssh-key (default)
85+
86+
Matched profile: work
87+
```
88+
89+
The `` shows which profile matches your current repo's identity.
90+
91+
---
92+
93+
## The "set it and forget it" mode
94+
95+
The best feature: git hooks that automatically apply the right profile before every commit and push.
96+
97+
```bash
98+
cd my-work-project
99+
git-profile install-hooks
100+
git-profile set-default work
101+
```
102+
103+
Now `git commit` in that repo always uses the `work` profile. No more thinking about it.
104+
105+
You can also set a global fallback:
106+
107+
```bash
108+
git-profile set-default personal --global
109+
```
110+
111+
Any repo without an explicit default falls back to `personal`.
112+
113+
---
114+
115+
## GPG signing per identity
116+
117+
If you sign commits, you probably have different GPG keys per identity. `git-profile` handles that too:
118+
119+
```bash
120+
git-profile add --id work \
121+
--name "Jane Dev" \
122+
--email jane@company.com \
123+
--gpg-key "ABC123DEF456" \
124+
--sign-commits
125+
```
126+
127+
When you run `git-profile use work`, it sets all four keys at once:
128+
129+
```ini
130+
user.name = Jane Dev
131+
user.email = jane@company.com
132+
user.signingkey = ABC123DEF456
133+
commit.gpgsign = true
134+
```
135+
136+
---
137+
138+
## Already have git configured? Import it
139+
140+
```bash
141+
git-profile import --id work --global
142+
```
143+
144+
Reads your current `~/.gitconfig` (name, email, SSH command, signing key) and creates a profile from it. Zero re-typing.
145+
146+
---
147+
148+
## Install
149+
150+
```bash
151+
# Homebrew
152+
brew install hapiio/tap/git-profile
153+
154+
# Go
155+
go install github.com/hapiio/git-profile@latest
156+
```
157+
158+
Binaries for Linux and macOS (Apple Silicon + Intel) are on the [releases page](https://github.com/hapiio/git-profile/releases).
159+
160+
Shell completions for bash, zsh, and fish are included.
161+
162+
---
163+
164+
## Why I built it
165+
166+
I switch between a full-time job, personal projects, and a few open-source repos every day. After the third time I pushed a commit with the wrong email to a client repo, I looked for a tool that handled all of it — SSH keys, GPG keys, auto-apply hooks — in one place. I didn't find one, so I built it.
167+
168+
The entire tool is a single static binary with no runtime dependencies. Profiles are stored as plain JSON in `~/.config/git-profile/config.json` so they're easy to back up or commit to a dotfiles repo.
169+
170+
---
171+
172+
Source and docs: **[github.com/hapiio/git-profile](https://github.com/hapiio/git-profile)**
173+
174+
Happy to hear feedback or feature requests in the issues.
175+
176+
---
177+
178+
> **Tags:** `git` `devtools` `golang` `productivity` `opensource`

docs/installation.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,34 @@ Download the latest binary for your platform from the [Releases](https://github.
1818

1919
### macOS (Apple Silicon)
2020

21+
2122
```bash
2223
curl -L https://github.com/hapiio/git-profile/releases/latest/download/git-profile_darwin_arm64.tar.gz \
2324
| tar -xz && mv git-profile /usr/local/bin/
2425
```
2526

27+
2628
### macOS (Intel)
2729

30+
2831
```bash
2932
curl -L https://github.com/hapiio/git-profile/releases/latest/download/git-profile_darwin_x86_64.tar.gz \
3033
| tar -xz && mv git-profile /usr/local/bin/
3134
```
3235

36+
3337
### Linux (amd64)
3438

39+
3540
```bash
3641
curl -L https://github.com/hapiio/git-profile/releases/latest/download/git-profile_linux_x86_64.tar.gz \
3742
| tar -xz && mv git-profile /usr/local/bin/
3843
```
3944

45+
4046
### Linux (arm64)
4147

48+
4249
```bash
4350
curl -L https://github.com/hapiio/git-profile/releases/latest/download/git-profile_linux_arm64.tar.gz \
4451
| tar -xz && mv git-profile /usr/local/bin/

0 commit comments

Comments
 (0)