Skip to content

Commit c9b062c

Browse files
committed
Update README to enhance Git configuration instructions and add GitHub/GitLab specific files
1 parent 748f61a commit c9b062c

1 file changed

Lines changed: 67 additions & 24 deletions

File tree

README.md

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,73 @@ But there's a set-and-forget solution to ensure your Git privacy.
1010
2. **Privacy Guardrail.** Set `useconfigonly = true` in your Git configuration to prevent falling back to your system username/hostname (e.g., `user@laptop.local`). If no email is set in the config, the commit will simply fail, prompting you to fix it.
1111
3. **Automatic Switching.** Use the conditional `[includeIf]` block with `**/*hostname.com/**` as a powerful glob pattern to match both HTTPS (`https://`) and SSH (`git@`) remote URLs for the respective hosts. This forces Git to use the correct no-reply email based purely on the repository's remote URL.
1212

13-
# Final Config
14-
15-
Copy and paste this content into your single global Git configuration file `~/.gitconfig`, **and don't forget replacing the PLACE\_HOLDERS:**
16-
17-
# =====================================================================
18-
# Global Git Config
19-
# =====================================================================
20-
[user]
21-
name = YOUR_FULL_NAME
22-
23-
# CRITICAL: Prevents accidental system email exposure if no
24-
# specific email is found in the conditional blocks below.
25-
useconfigonly = true
26-
27-
# =====================================================================
28-
# Conditional Emails
29-
# =====================================================================
30-
[includeIf "hasconfig:remote.*.url:**/*github.com/**"]
31-
[user]
32-
email = YOUR_GITHUB_ID+USERNAME@users.noreply.github.com
33-
# =====================================================================
34-
[includeIf "hasconfig:remote.*.url:**/*gitlab.com/**"]
35-
[user]
36-
email = YOUR_GITLAB_ID-USERNAME@users.noreply.gitlab.com
13+
# Final Config Files
14+
15+
You'll need the following configuration files. Replace all `PLACE_HOLDER` values with your actual information.
16+
17+
## `.gitconfig` (Global Git Configuration)
18+
19+
```ini
20+
# ====================================================================
21+
# Global Git Configuration (Usually ~/.gitconfig)
22+
#
23+
# To use this example:
24+
# 1. Save this file as ~/.gitconfig
25+
# 2. Replace all PLACE_HOLDER values (e.g., YOUR_FULL_NAME)
26+
# 3. Repeat for .gitconfig-github and .gitconfig-gitlab as necessary
27+
# ====================================================================
28+
29+
[user]
30+
# Set your default name for all commits.
31+
name = YOUR_FULL_NAME
32+
33+
# CRITICAL: Prevents accidental exposure of system email if no
34+
# specific email is found in the conditional blocks below.
35+
useconfigonly = true
36+
37+
# --------------------------------------------------------------------
38+
# CONDITIONAL OVERRIDES
39+
# These allow you to use different `user.email` based on the URL of
40+
# the remote repository.
41+
# ====================================================================
42+
[includeIf "hasconfig:remote.*.url:**/*github.com/**"]
43+
path = .gitconfig-github
44+
45+
[includeIf "hasconfig:remote.*.url:**/*gitlab.com/**"]
46+
path = .gitconfig-gitlab
47+
```
48+
49+
## `.gitconfig-github` (GitHub-Specific Configuration)
50+
51+
```ini
52+
# ====================================================================
53+
# GitHub-specific Git configuration
54+
#
55+
# To use this example:
56+
# 1. Get your unique GitHub commit email:
57+
# https://docs.github.com/en/account-and-profile/how-tos/email-preferences/setting-your-commit-email-address
58+
# 2. Copy this file next to your `~/.gitconfig` and replace email below
59+
# ====================================================================
60+
61+
[user]
62+
email = YOUR_GITHUB_ID+USERNAME@users.noreply.github.com
63+
```
64+
65+
## `.gitconfig-gitlab` (GitLab-Specific Configuration)
66+
67+
```ini
68+
# ====================================================================
69+
# GitLab-specific Git configuration
70+
#
71+
# To use this example:
72+
# 1. Get your unique GitLab commit email:
73+
# https://docs.gitlab.com/user/profile/#use-an-automatically-generated-private-commit-email
74+
# 2. Copy this file next to your `~/.gitconfig` and replace email below
75+
# ====================================================================
76+
77+
[user]
78+
email = YOUR_GITLAB_ID-USERNAME@users.noreply.gitlab.com
79+
```
3780

3881
# How to Verify
3982

0 commit comments

Comments
 (0)