Skip to content

Commit a4dccc5

Browse files
brabojclaude
andcommitted
docs: add credentials recipe to playbook
Covers credential helpers (cache, store, GCM), HTTPS personal access tokens, SSH vs HTTPS comparison, security considerations, and gotchas. Added to playbook index under Remote section. Closes #169 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 72c9028 commit a4dccc5

2 files changed

Lines changed: 151 additions & 0 deletions

File tree

chapters/07-playbook.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ For definitions, see [Glossary](09-glossary.md).
4040
| [Remote Management](playbook/remote-management.md) | Add, rename, remove remotes, switch URL, SSH setup |
4141
| [SSH Setup](playbook/ssh-setup.md) | Key generation, agent, GitHub registration, troubleshooting |
4242
| [Bare Repositories](playbook/bare-repositories.md) | Create, clone, convert, and use bare repos as local remotes |
43+
| [Credentials](playbook/credentials.md) | Credential helpers (cache, store, GCM), HTTPS tokens, security |
4344

4445
## Project Structure
4546

chapters/recipes/credentials.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
---
2+
title: "Credentials"
3+
description: "Git recipes for storing and managing credentials — credential helpers (cache, store, manager), HTTPS tokens, SSH keys, and security considerations."
4+
section: "playbook/credentials"
5+
order: 94
6+
---
7+
8+
## Credentials
9+
10+
Every time you push to or pull from a remote over HTTPS, Git needs to
11+
authenticate you. By default, it asks for your username and password
12+
(or token) on every operation. Credential helpers let you store these
13+
credentials so you do not have to type them each time.
14+
15+
For SSH-based authentication, see [SSH Setup](../ssh-setup/).
16+
17+
### HTTPS vs SSH
18+
19+
| | HTTPS | SSH |
20+
|---|---|---|
21+
| Setup | Simple — works immediately | Requires key generation and registration |
22+
| Authentication | Username + token (or password) | Private key on your machine |
23+
| Credential storage | Via credential helpers (below) | SSH agent holds the key in memory |
24+
| Firewall-friendly | Yes — uses port 443 | May be blocked on port 22 |
25+
26+
HTTPS is easier to start with. SSH avoids credential prompts entirely
27+
once configured. Most developers use SSH for repositories they work
28+
with regularly, and HTTPS for quick one-off clones.
29+
30+
### Credential helpers
31+
32+
A credential helper is a program that stores your credentials so Git
33+
can retrieve them automatically. Git ships with two built-in helpers
34+
and supports external ones.
35+
36+
#### cache
37+
38+
Stores credentials in memory for a limited time (default: 15 minutes).
39+
Nothing is written to disk.
40+
41+
```text
42+
$ git config --global credential.helper cache
43+
44+
# extend to 1 hour (3600 seconds)
45+
$ git config --global credential.helper 'cache --timeout=3600'
46+
```
47+
48+
Best for: shared machines where you do not want credentials on disk.
49+
50+
#### store
51+
52+
Saves credentials in a plaintext file (`~/.git-credentials`). They
53+
persist across reboots but are **not encrypted** — anyone with access
54+
to your home directory can read them.
55+
56+
```text
57+
$ git config --global credential.helper store
58+
```
59+
60+
After the next successful authentication, Git writes the credentials:
61+
62+
```text
63+
$ cat ~/.git-credentials
64+
https://username:ghp_abc123token@github.com
65+
```
66+
67+
Best for: personal machines where convenience matters more than
68+
maximum security. Acceptable when the machine has full-disk encryption.
69+
70+
#### Git Credential Manager
71+
72+
[Git Credential Manager](https://github.com/git-ecosystem/git-credential-manager)
73+
(GCM) is an external helper that stores credentials in your operating
74+
system's secure storage — Windows Credential Manager, macOS Keychain,
75+
or Linux Secret Service.
76+
77+
```text
78+
$ git config --global credential.helper manager
79+
```
80+
81+
GCM is included with Git for Windows by default. On macOS and Linux,
82+
install it separately. It supports multi-factor authentication and
83+
OAuth flows for GitHub, GitLab, Bitbucket, and Azure DevOps.
84+
85+
Best for: most developers — encrypted storage, cross-platform, handles
86+
modern authentication flows.
87+
88+
### Check your current helper
89+
90+
```text
91+
$ git config --global credential.helper
92+
manager
93+
```
94+
95+
If this returns nothing, no helper is configured and Git will prompt
96+
every time.
97+
98+
### HTTPS personal access tokens
99+
100+
GitHub, GitLab, and Bitbucket no longer accept account passwords for
101+
HTTPS Git operations. You need a **personal access token** (PAT)
102+
instead.
103+
104+
To create one on GitHub:
105+
106+
1. Go to **Settings > Developer settings > Personal access tokens > Tokens (classic)**
107+
2. Click **Generate new token**
108+
3. Select scopes — `repo` is enough for push/pull
109+
4. Copy the token — you will not see it again
110+
111+
Use the token as your password when Git prompts:
112+
113+
```text
114+
$ git push origin main
115+
Username: your-username
116+
Password: ghp_abc123... ← paste the token here
117+
```
118+
119+
If you have a credential helper configured, Git stores the token
120+
after the first successful use.
121+
122+
### Security considerations
123+
124+
| Helper | Storage | Risk |
125+
|--------|---------|------|
126+
| cache | Memory only, expires | Low — gone after timeout or reboot |
127+
| store | Plaintext file on disk | High — readable by anyone with file access |
128+
| manager (GCM) | OS encrypted keychain | Low — protected by OS-level security |
129+
130+
Recommendations:
131+
132+
- **Never commit credentials** to a repository — not in code, not in
133+
config files, not in `.env` files that are tracked
134+
- **Prefer GCM or SSH** over the plaintext `store` helper
135+
- **Rotate tokens regularly** — treat them like passwords
136+
- **Use the minimum scope** when creating tokens — `repo` is enough
137+
for most workflows
138+
- **Revoke tokens immediately** if a machine is lost or compromised
139+
140+
### Gotchas
141+
142+
- **`store` keeps credentials in plaintext.** If you switch from
143+
`store` to `manager`, delete `~/.git-credentials` to remove the
144+
old plaintext file.
145+
- **Credential helpers are per-protocol.** An HTTPS helper does not
146+
affect SSH authentication, and vice versa.
147+
- **Multiple helpers can conflict.** If Git behaves unexpectedly,
148+
check for stacked helpers: `git config --global --get-all credential.helper`.
149+
- **Tokens expire.** If pushes suddenly fail with 401 errors, your
150+
token may have expired — generate a new one.

0 commit comments

Comments
 (0)