cfsa-antigravity 2.0.0 → 2.2.0
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 +14 -0
- package/package.json +1 -1
- package/template/.agent/instructions/commands.md +8 -32
- package/template/.agent/instructions/example.md +21 -0
- package/template/.agent/instructions/patterns.md +3 -3
- package/template/.agent/instructions/tech-stack.md +71 -23
- package/template/.agent/instructions/workflow.md +12 -1
- package/template/.agent/rules/completion-checklist.md +6 -0
- package/template/.agent/rules/security-first.md +3 -3
- package/template/.agent/rules/vertical-slices.md +1 -1
- package/template/.agent/skill-library/MANIFEST.md +6 -0
- package/template/.agent/skill-library/stack/devops/git-advanced/SKILL.md +972 -0
- package/template/.agent/skill-library/stack/devops/git-workflow/SKILL.md +420 -0
- package/template/.agent/skills/api-versioning/SKILL.md +44 -298
- package/template/.agent/skills/api-versioning/references/typescript.md +157 -0
- package/template/.agent/skills/architecture-mapping/SKILL.md +13 -13
- package/template/.agent/skills/bootstrap-agents/SKILL.md +151 -152
- package/template/.agent/skills/clean-code/SKILL.md +64 -118
- package/template/.agent/skills/clean-code/references/typescript.md +126 -0
- package/template/.agent/skills/database-schema-design/SKILL.md +93 -317
- package/template/.agent/skills/database-schema-design/references/relational.md +228 -0
- package/template/.agent/skills/error-handling-patterns/SKILL.md +62 -557
- package/template/.agent/skills/error-handling-patterns/references/go.md +162 -0
- package/template/.agent/skills/error-handling-patterns/references/python.md +262 -0
- package/template/.agent/skills/error-handling-patterns/references/rust.md +112 -0
- package/template/.agent/skills/error-handling-patterns/references/typescript.md +178 -0
- package/template/.agent/skills/idea-extraction/SKILL.md +322 -224
- package/template/.agent/skills/logging-best-practices/SKILL.md +108 -767
- package/template/.agent/skills/logging-best-practices/references/go.md +49 -0
- package/template/.agent/skills/logging-best-practices/references/python.md +52 -0
- package/template/.agent/skills/logging-best-practices/references/typescript.md +215 -0
- package/template/.agent/skills/migration-management/SKILL.md +127 -311
- package/template/.agent/skills/migration-management/references/relational.md +214 -0
- package/template/.agent/skills/parallel-feature-development/SKILL.md +34 -43
- package/template/.agent/skills/pipeline-rubrics/references/be-rubric.md +1 -1
- package/template/.agent/skills/pipeline-rubrics/references/ia-rubric.md +2 -2
- package/template/.agent/skills/pipeline-rubrics/references/scoring.md +1 -1
- package/template/.agent/skills/pipeline-rubrics/references/vision-rubric.md +2 -1
- package/template/.agent/skills/prd-templates/SKILL.md +23 -6
- package/template/.agent/skills/prd-templates/references/be-spec-template.md +2 -2
- package/template/.agent/skills/prd-templates/references/decomposition-templates.md +2 -2
- package/template/.agent/skills/prd-templates/references/engineering-standards-template.md +2 -0
- package/template/.agent/skills/prd-templates/references/fe-spec-template.md +1 -1
- package/template/.agent/skills/prd-templates/references/fractal-cx-template.md +58 -0
- package/template/.agent/skills/prd-templates/references/fractal-feature-template.md +93 -0
- package/template/.agent/skills/prd-templates/references/fractal-node-index-template.md +55 -0
- package/template/.agent/skills/prd-templates/references/ideation-crosscut-template.md +26 -47
- package/template/.agent/skills/prd-templates/references/ideation-index-template.md +47 -31
- package/template/.agent/skills/prd-templates/references/operational-templates.md +1 -1
- package/template/.agent/skills/prd-templates/references/placeholder-workflow-mapping.md +50 -21
- package/template/.agent/skills/prd-templates/references/skill-loading-protocol.md +32 -0
- package/template/.agent/skills/prd-templates/references/slice-completion-gates.md +29 -0
- package/template/.agent/skills/prd-templates/references/spec-coverage-sweep.md +3 -3
- package/template/.agent/skills/prd-templates/references/tdd-testing-policy.md +39 -0
- package/template/.agent/skills/prd-templates/references/vision-template.md +8 -8
- package/template/.agent/skills/regex-patterns/SKILL.md +122 -540
- package/template/.agent/skills/regex-patterns/references/go.md +44 -0
- package/template/.agent/skills/regex-patterns/references/javascript.md +63 -0
- package/template/.agent/skills/regex-patterns/references/python.md +77 -0
- package/template/.agent/skills/regex-patterns/references/rust.md +43 -0
- package/template/.agent/skills/resolve-ambiguity/SKILL.md +1 -1
- package/template/.agent/skills/session-continuity/SKILL.md +11 -9
- package/template/.agent/skills/session-continuity/protocols/02-progress-generation.md +2 -2
- package/template/.agent/skills/session-continuity/protocols/04-pattern-extraction.md +1 -1
- package/template/.agent/skills/session-continuity/protocols/05-session-close.md +1 -1
- package/template/.agent/skills/session-continuity/protocols/09-parallel-claim.md +1 -1
- package/template/.agent/skills/session-continuity/protocols/10-placeholder-verification-gate.md +57 -78
- package/template/.agent/skills/session-continuity/protocols/11-parallel-synthesis.md +1 -1
- package/template/.agent/skills/spec-writing/SKILL.md +1 -1
- package/template/.agent/skills/tdd-workflow/SKILL.md +94 -317
- package/template/.agent/skills/tdd-workflow/references/typescript.md +231 -0
- package/template/.agent/skills/testing-strategist/SKILL.md +74 -687
- package/template/.agent/skills/testing-strategist/references/typescript.md +328 -0
- package/template/.agent/skills/workflow-automation/SKILL.md +62 -154
- package/template/.agent/skills/workflow-automation/references/inngest.md +88 -0
- package/template/.agent/skills/workflow-automation/references/temporal.md +64 -0
- package/template/.agent/workflows/bootstrap-agents-fill.md +85 -143
- package/template/.agent/workflows/bootstrap-agents-provision.md +90 -107
- package/template/.agent/workflows/create-prd-architecture.md +23 -16
- package/template/.agent/workflows/create-prd-compile.md +11 -12
- package/template/.agent/workflows/create-prd-design-system.md +1 -1
- package/template/.agent/workflows/create-prd-security.md +9 -11
- package/template/.agent/workflows/create-prd-stack.md +10 -4
- package/template/.agent/workflows/create-prd.md +9 -9
- package/template/.agent/workflows/decompose-architecture-structure.md +4 -6
- package/template/.agent/workflows/decompose-architecture-validate.md +18 -1
- package/template/.agent/workflows/decompose-architecture.md +18 -3
- package/template/.agent/workflows/evolve-contract.md +11 -11
- package/template/.agent/workflows/evolve-feature-classify.md +14 -6
- package/template/.agent/workflows/ideate-discover.md +72 -107
- package/template/.agent/workflows/ideate-extract.md +84 -63
- package/template/.agent/workflows/ideate-validate.md +26 -22
- package/template/.agent/workflows/ideate.md +9 -9
- package/template/.agent/workflows/implement-slice-setup.md +25 -23
- package/template/.agent/workflows/implement-slice-tdd.md +73 -89
- package/template/.agent/workflows/implement-slice.md +4 -4
- package/template/.agent/workflows/plan-phase-preflight.md +6 -2
- package/template/.agent/workflows/plan-phase-write.md +6 -8
- package/template/.agent/workflows/remediate-pipeline-assess.md +2 -1
- package/template/.agent/workflows/resolve-ambiguity.md +2 -2
- package/template/.agent/workflows/update-architecture-map.md +22 -5
- package/template/.agent/workflows/validate-phase-quality.md +155 -0
- package/template/.agent/workflows/validate-phase-readiness.md +167 -0
- package/template/.agent/workflows/validate-phase.md +19 -157
- package/template/.agent/workflows/verify-infrastructure.md +10 -10
- package/template/.agent/workflows/write-architecture-spec-design.md +23 -14
- package/template/.agent/workflows/write-be-spec-classify.md +25 -21
- package/template/.agent/workflows/write-be-spec.md +1 -1
- package/template/.agent/workflows/write-fe-spec-classify.md +6 -12
- package/template/.agent/workflows/write-fe-spec-write.md +1 -1
- package/template/AGENTS.md +6 -2
- package/template/GEMINI.md +5 -3
- package/template/docs/README.md +10 -10
- package/template/docs/kit-architecture.md +126 -33
- package/template/docs/plans/ideation/README.md +8 -3
- package/template/.agent/skills/prd-templates/references/ideation-domain-template.md +0 -55
|
@@ -0,0 +1,972 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: git-advanced
|
|
3
|
+
description: "Comprehensive advanced Git patterns guide covering interactive rebase, cherry-pick, bisect for bug hunting, worktrees, reflog for recovery, stash management, submodules vs subtrees, hooks (pre-commit, commit-msg, pre-push), conventional commits, merge strategies, branch naming, git attributes (LFS, diff drivers), blame/log archaeology, patch workflow, sparse checkout, filter-repo, signing commits, and performance optimizations. Use when performing complex Git operations beyond basic add/commit/push."
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Advanced Git Patterns
|
|
8
|
+
|
|
9
|
+
## 1. Interactive Rebase
|
|
10
|
+
|
|
11
|
+
### Rewriting History
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# Rebase last N commits interactively
|
|
15
|
+
git rebase -i HEAD~5
|
|
16
|
+
|
|
17
|
+
# Rebase onto a branch
|
|
18
|
+
git rebase -i main
|
|
19
|
+
|
|
20
|
+
# The editor opens with a list of commits:
|
|
21
|
+
# pick abc1234 Add user model
|
|
22
|
+
# pick def5678 Fix typo in user model
|
|
23
|
+
# pick ghi9012 Add user validation
|
|
24
|
+
# pick jkl3456 WIP debugging
|
|
25
|
+
# pick mno7890 Add user tests
|
|
26
|
+
|
|
27
|
+
# Commands:
|
|
28
|
+
# pick = use commit as-is
|
|
29
|
+
# reword = use commit but edit the message
|
|
30
|
+
# edit = pause to amend the commit
|
|
31
|
+
# squash = meld into previous commit (keep message)
|
|
32
|
+
# fixup = meld into previous commit (discard message)
|
|
33
|
+
# drop = remove commit entirely
|
|
34
|
+
# exec = run a shell command
|
|
35
|
+
|
|
36
|
+
# Example: squash WIP commit into the previous one:
|
|
37
|
+
# pick abc1234 Add user model
|
|
38
|
+
# pick def5678 Fix typo in user model
|
|
39
|
+
# pick ghi9012 Add user validation
|
|
40
|
+
# fixup jkl3456 WIP debugging
|
|
41
|
+
# pick mno7890 Add user tests
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Autosquash
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Create a fixup commit (will auto-squash into target)
|
|
48
|
+
git commit --fixup=abc1234
|
|
49
|
+
|
|
50
|
+
# Create a squash commit (auto-squash with message editing)
|
|
51
|
+
git commit --squash=abc1234
|
|
52
|
+
|
|
53
|
+
# Run rebase with autosquash
|
|
54
|
+
git rebase -i --autosquash main
|
|
55
|
+
|
|
56
|
+
# Enable autosquash by default
|
|
57
|
+
git config --global rebase.autosquash true
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Rebase onto
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# Move a branch from one base to another
|
|
64
|
+
# Before: A-B-C-D (main)
|
|
65
|
+
# \
|
|
66
|
+
# E-F-G (feature, branched from C)
|
|
67
|
+
|
|
68
|
+
git rebase --onto D C feature
|
|
69
|
+
|
|
70
|
+
# After: A-B-C-D (main)
|
|
71
|
+
# \
|
|
72
|
+
# E'-F'-G' (feature, now based on D)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Abort and Continue
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# If conflicts arise during rebase
|
|
79
|
+
git rebase --abort # Cancel the entire rebase
|
|
80
|
+
git rebase --continue # After resolving conflicts, continue
|
|
81
|
+
git rebase --skip # Skip the current commit
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 2. Cherry-Pick
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# Apply a specific commit to the current branch
|
|
90
|
+
git cherry-pick abc1234
|
|
91
|
+
|
|
92
|
+
# Cherry-pick without committing (stage changes only)
|
|
93
|
+
git cherry-pick --no-commit abc1234
|
|
94
|
+
|
|
95
|
+
# Cherry-pick a range of commits
|
|
96
|
+
git cherry-pick abc1234..def5678 # Exclusive of abc1234
|
|
97
|
+
git cherry-pick abc1234^..def5678 # Inclusive of abc1234
|
|
98
|
+
|
|
99
|
+
# Cherry-pick from another remote
|
|
100
|
+
git fetch upstream
|
|
101
|
+
git cherry-pick upstream/main~3
|
|
102
|
+
|
|
103
|
+
# Resolve conflicts during cherry-pick
|
|
104
|
+
git cherry-pick --continue # After resolving
|
|
105
|
+
git cherry-pick --abort # Cancel
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### When to Use Cherry-Pick
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
GOOD use cases:
|
|
112
|
+
- Backporting a bug fix to a release branch
|
|
113
|
+
- Extracting a single commit from a long-lived feature branch
|
|
114
|
+
- Applying a hotfix that was made on the wrong branch
|
|
115
|
+
|
|
116
|
+
AVOID:
|
|
117
|
+
- Cherry-picking many commits (use merge or rebase instead)
|
|
118
|
+
- Cherry-picking between branches that will be merged (creates duplicates)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## 3. Git Bisect (Bug Hunting)
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Start bisecting
|
|
127
|
+
git bisect start
|
|
128
|
+
|
|
129
|
+
# Mark current commit as bad (has the bug)
|
|
130
|
+
git bisect bad
|
|
131
|
+
|
|
132
|
+
# Mark a known good commit (did not have the bug)
|
|
133
|
+
git bisect good v1.0.0
|
|
134
|
+
|
|
135
|
+
# Git checks out a commit halfway between good and bad.
|
|
136
|
+
# Test it, then mark:
|
|
137
|
+
git bisect good # Bug not present
|
|
138
|
+
# or
|
|
139
|
+
git bisect bad # Bug present
|
|
140
|
+
|
|
141
|
+
# Git narrows the range and checks out the next commit.
|
|
142
|
+
# Repeat until the first bad commit is found.
|
|
143
|
+
|
|
144
|
+
# Reset when done
|
|
145
|
+
git bisect reset
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Automated Bisect
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
# Run a script to automatically test each commit
|
|
152
|
+
git bisect start HEAD v1.0.0
|
|
153
|
+
git bisect run npm test
|
|
154
|
+
|
|
155
|
+
# The script must exit 0 for "good" and non-zero for "bad"
|
|
156
|
+
# Git will find the first commit that broke the tests
|
|
157
|
+
|
|
158
|
+
# With a custom test script
|
|
159
|
+
git bisect run ./test-specific-bug.sh
|
|
160
|
+
|
|
161
|
+
# Skip untestable commits (e.g., won't compile)
|
|
162
|
+
git bisect skip
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Bisect with a Test Command
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
# Example: find when a specific test started failing
|
|
169
|
+
git bisect start HEAD v2.0.0
|
|
170
|
+
git bisect run sh -c 'npm run build && npm test -- --grep "user login"'
|
|
171
|
+
|
|
172
|
+
# Example: find when a file was deleted
|
|
173
|
+
git bisect start HEAD v1.0.0
|
|
174
|
+
git bisect run sh -c 'test -f src/utils/helpers.ts'
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## 4. Worktrees
|
|
180
|
+
|
|
181
|
+
### Multiple Working Directories from One Repo
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
# List existing worktrees
|
|
185
|
+
git worktree list
|
|
186
|
+
|
|
187
|
+
# Create a new worktree for a branch
|
|
188
|
+
git worktree add ../project-feature feature-branch
|
|
189
|
+
|
|
190
|
+
# Create a new worktree with a new branch
|
|
191
|
+
git worktree add -b hotfix-123 ../project-hotfix main
|
|
192
|
+
|
|
193
|
+
# Remove a worktree
|
|
194
|
+
git worktree remove ../project-feature
|
|
195
|
+
|
|
196
|
+
# Prune stale worktree metadata
|
|
197
|
+
git worktree prune
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Use Cases
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
- Review a PR while your main worktree has uncommitted changes
|
|
204
|
+
- Run tests on one branch while developing on another
|
|
205
|
+
- Compare behavior between branches side by side
|
|
206
|
+
- Build documentation from one branch while coding on another
|
|
207
|
+
|
|
208
|
+
# Directory structure:
|
|
209
|
+
# ~/projects/myapp/ (main worktree)
|
|
210
|
+
# ~/projects/myapp-feature/ (feature worktree)
|
|
211
|
+
# ~/projects/myapp-hotfix/ (hotfix worktree)
|
|
212
|
+
# All share the same .git directory (disk-efficient)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## 5. Reflog (Recovery)
|
|
218
|
+
|
|
219
|
+
### View the Reflog
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
# Show reflog for HEAD (all recent actions)
|
|
223
|
+
git reflog
|
|
224
|
+
|
|
225
|
+
# Output example:
|
|
226
|
+
# abc1234 HEAD@{0}: commit: Add user tests
|
|
227
|
+
# def5678 HEAD@{1}: rebase (finish): returning to refs/heads/feature
|
|
228
|
+
# ghi9012 HEAD@{2}: rebase (pick): Add validation
|
|
229
|
+
# jkl3456 HEAD@{3}: reset: moving to HEAD~3
|
|
230
|
+
# mno7890 HEAD@{4}: commit: WIP changes (now "lost")
|
|
231
|
+
|
|
232
|
+
# Show reflog for a specific branch
|
|
233
|
+
git reflog show feature-branch
|
|
234
|
+
|
|
235
|
+
# Show reflog with timestamps
|
|
236
|
+
git reflog --date=iso
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Recovery Scenarios
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
# Recover from accidental reset --hard
|
|
243
|
+
git reflog
|
|
244
|
+
# Find the commit hash before the reset
|
|
245
|
+
git reset --hard HEAD@{2}
|
|
246
|
+
|
|
247
|
+
# Recover a deleted branch
|
|
248
|
+
git reflog
|
|
249
|
+
# Find the last commit on the deleted branch
|
|
250
|
+
git branch recovered-branch abc1234
|
|
251
|
+
|
|
252
|
+
# Recover from a bad rebase
|
|
253
|
+
git reflog
|
|
254
|
+
# Find HEAD before the rebase started
|
|
255
|
+
git reset --hard HEAD@{5}
|
|
256
|
+
|
|
257
|
+
# Recover dropped stash
|
|
258
|
+
git fsck --unreachable | grep commit
|
|
259
|
+
git show <commit-hash>
|
|
260
|
+
git stash apply <commit-hash>
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Reflog Expiry
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
# Reflog entries expire after 90 days (default)
|
|
267
|
+
# Unreachable entries expire after 30 days (default)
|
|
268
|
+
|
|
269
|
+
# Change expiry
|
|
270
|
+
git config gc.reflogExpire 180.days
|
|
271
|
+
git config gc.reflogExpireUnreachable 90.days
|
|
272
|
+
|
|
273
|
+
# Manually expire
|
|
274
|
+
git reflog expire --expire=now --all
|
|
275
|
+
git gc --prune=now
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## 6. Stash Management
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
# Stash current changes (tracked files only)
|
|
284
|
+
git stash
|
|
285
|
+
|
|
286
|
+
# Stash with a descriptive message
|
|
287
|
+
git stash push -m "WIP: user authentication refactor"
|
|
288
|
+
|
|
289
|
+
# Stash including untracked files
|
|
290
|
+
git stash push -u -m "Include new config files"
|
|
291
|
+
|
|
292
|
+
# Stash including ignored files too
|
|
293
|
+
git stash push -a -m "Everything including ignored"
|
|
294
|
+
|
|
295
|
+
# Stash specific files
|
|
296
|
+
git stash push -m "Only these files" src/auth.ts src/login.tsx
|
|
297
|
+
|
|
298
|
+
# List stashes
|
|
299
|
+
git stash list
|
|
300
|
+
# stash@{0}: On feature: WIP: user authentication refactor
|
|
301
|
+
# stash@{1}: On main: Quick experiment
|
|
302
|
+
|
|
303
|
+
# Apply most recent stash (keep it in stash list)
|
|
304
|
+
git stash apply
|
|
305
|
+
|
|
306
|
+
# Apply and remove from stash list
|
|
307
|
+
git stash pop
|
|
308
|
+
|
|
309
|
+
# Apply a specific stash
|
|
310
|
+
git stash apply stash@{2}
|
|
311
|
+
|
|
312
|
+
# Show stash contents (diff)
|
|
313
|
+
git stash show -p stash@{0}
|
|
314
|
+
|
|
315
|
+
# Create a branch from a stash
|
|
316
|
+
git stash branch new-feature stash@{0}
|
|
317
|
+
|
|
318
|
+
# Drop a specific stash
|
|
319
|
+
git stash drop stash@{1}
|
|
320
|
+
|
|
321
|
+
# Clear all stashes
|
|
322
|
+
git stash clear
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
327
|
+
## 7. Submodules vs Subtrees
|
|
328
|
+
|
|
329
|
+
### Submodules
|
|
330
|
+
|
|
331
|
+
```bash
|
|
332
|
+
# Add a submodule
|
|
333
|
+
git submodule add https://github.com/user/library.git lib/library
|
|
334
|
+
|
|
335
|
+
# Clone a repo with submodules
|
|
336
|
+
git clone --recurse-submodules https://github.com/user/project.git
|
|
337
|
+
|
|
338
|
+
# Initialize submodules after cloning
|
|
339
|
+
git submodule update --init --recursive
|
|
340
|
+
|
|
341
|
+
# Update submodule to latest upstream commit
|
|
342
|
+
cd lib/library
|
|
343
|
+
git pull origin main
|
|
344
|
+
cd ../..
|
|
345
|
+
git add lib/library
|
|
346
|
+
git commit -m "Update library submodule to latest"
|
|
347
|
+
|
|
348
|
+
# Update all submodules
|
|
349
|
+
git submodule update --remote --merge
|
|
350
|
+
|
|
351
|
+
# Remove a submodule
|
|
352
|
+
git submodule deinit lib/library
|
|
353
|
+
git rm lib/library
|
|
354
|
+
rm -rf .git/modules/lib/library
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### Subtrees
|
|
358
|
+
|
|
359
|
+
```bash
|
|
360
|
+
# Add a subtree (no .gitmodules file, simpler for contributors)
|
|
361
|
+
git subtree add --prefix=lib/library https://github.com/user/library.git main --squash
|
|
362
|
+
|
|
363
|
+
# Pull updates from upstream
|
|
364
|
+
git subtree pull --prefix=lib/library https://github.com/user/library.git main --squash
|
|
365
|
+
|
|
366
|
+
# Push changes back to upstream
|
|
367
|
+
git subtree push --prefix=lib/library https://github.com/user/library.git main
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### Comparison
|
|
371
|
+
|
|
372
|
+
```
|
|
373
|
+
Submodules:
|
|
374
|
+
+ Exact version pinning
|
|
375
|
+
+ Keeps history separate
|
|
376
|
+
+ Smaller repo size (only metadata stored)
|
|
377
|
+
- Requires extra commands to clone/update
|
|
378
|
+
- Contributors must understand submodule workflow
|
|
379
|
+
- Detached HEAD inside submodule
|
|
380
|
+
|
|
381
|
+
Subtrees:
|
|
382
|
+
+ No special commands for contributors (just clone and go)
|
|
383
|
+
+ Changes to subtree are regular commits
|
|
384
|
+
+ Works without network access
|
|
385
|
+
- Larger repo size (full subtree code in repo)
|
|
386
|
+
- Pushing back upstream is manual
|
|
387
|
+
- History can become cluttered
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
## 8. Git Hooks
|
|
393
|
+
|
|
394
|
+
### Client-Side Hooks
|
|
395
|
+
|
|
396
|
+
```bash
|
|
397
|
+
# Hooks live in .git/hooks/ (not version-controlled by default)
|
|
398
|
+
# Use a tool like Husky, lefthook, or simple-git-hooks to share hooks
|
|
399
|
+
|
|
400
|
+
# pre-commit: runs before commit is created
|
|
401
|
+
# Use case: lint, format, run tests
|
|
402
|
+
.git/hooks/pre-commit
|
|
403
|
+
|
|
404
|
+
# commit-msg: runs after message is entered
|
|
405
|
+
# Use case: enforce conventional commit format
|
|
406
|
+
.git/hooks/commit-msg
|
|
407
|
+
|
|
408
|
+
# pre-push: runs before push
|
|
409
|
+
# Use case: run full test suite
|
|
410
|
+
.git/hooks/pre-push
|
|
411
|
+
|
|
412
|
+
# prepare-commit-msg: runs before editor opens
|
|
413
|
+
# Use case: prepend branch name to commit message
|
|
414
|
+
.git/hooks/prepare-commit-msg
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
### pre-commit Hook Example
|
|
418
|
+
|
|
419
|
+
```bash
|
|
420
|
+
#!/bin/sh
|
|
421
|
+
# .git/hooks/pre-commit
|
|
422
|
+
|
|
423
|
+
# Run linter on staged files only
|
|
424
|
+
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(ts|tsx)$')
|
|
425
|
+
|
|
426
|
+
if [ -n "$STAGED_FILES" ]; then
|
|
427
|
+
npx eslint $STAGED_FILES
|
|
428
|
+
if [ $? -ne 0 ]; then
|
|
429
|
+
echo "Lint errors found. Fix them before committing."
|
|
430
|
+
exit 1
|
|
431
|
+
fi
|
|
432
|
+
fi
|
|
433
|
+
|
|
434
|
+
# Run type check
|
|
435
|
+
npx tsc --noEmit
|
|
436
|
+
if [ $? -ne 0 ]; then
|
|
437
|
+
echo "Type errors found. Fix them before committing."
|
|
438
|
+
exit 1
|
|
439
|
+
fi
|
|
440
|
+
|
|
441
|
+
exit 0
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
### commit-msg Hook (Conventional Commits)
|
|
445
|
+
|
|
446
|
+
```bash
|
|
447
|
+
#!/bin/sh
|
|
448
|
+
# .git/hooks/commit-msg
|
|
449
|
+
|
|
450
|
+
COMMIT_MSG_FILE=$1
|
|
451
|
+
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE")
|
|
452
|
+
|
|
453
|
+
# Conventional commit pattern
|
|
454
|
+
PATTERN="^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(.+\))?: .{1,72}"
|
|
455
|
+
|
|
456
|
+
if ! echo "$COMMIT_MSG" | grep -qE "$PATTERN"; then
|
|
457
|
+
echo "ERROR: Commit message does not follow Conventional Commits format."
|
|
458
|
+
echo ""
|
|
459
|
+
echo "Expected: <type>(<scope>): <description>"
|
|
460
|
+
echo "Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"
|
|
461
|
+
echo ""
|
|
462
|
+
echo "Examples:"
|
|
463
|
+
echo " feat(auth): add password reset flow"
|
|
464
|
+
echo " fix: resolve race condition in queue worker"
|
|
465
|
+
echo " docs(readme): update installation instructions"
|
|
466
|
+
exit 1
|
|
467
|
+
fi
|
|
468
|
+
|
|
469
|
+
exit 0
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
### Husky Setup (Shared Hooks)
|
|
473
|
+
|
|
474
|
+
```bash
|
|
475
|
+
# Install
|
|
476
|
+
npm install --save-dev husky
|
|
477
|
+
|
|
478
|
+
# Initialize
|
|
479
|
+
npx husky init
|
|
480
|
+
|
|
481
|
+
# Add a pre-commit hook
|
|
482
|
+
echo "npx lint-staged" > .husky/pre-commit
|
|
483
|
+
|
|
484
|
+
# Add a commit-msg hook
|
|
485
|
+
echo 'npx --no-install commitlint --edit "$1"' > .husky/commit-msg
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
---
|
|
489
|
+
|
|
490
|
+
## 9. Conventional Commits
|
|
491
|
+
|
|
492
|
+
```
|
|
493
|
+
<type>(<scope>): <description>
|
|
494
|
+
|
|
495
|
+
[optional body]
|
|
496
|
+
|
|
497
|
+
[optional footer(s)]
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
### Types
|
|
501
|
+
|
|
502
|
+
```
|
|
503
|
+
feat: New feature (MINOR in semver)
|
|
504
|
+
fix: Bug fix (PATCH in semver)
|
|
505
|
+
docs: Documentation only
|
|
506
|
+
style: Formatting, semicolons, etc. (not CSS)
|
|
507
|
+
refactor: Code change that neither fixes nor adds
|
|
508
|
+
perf: Performance improvement
|
|
509
|
+
test: Adding or correcting tests
|
|
510
|
+
build: Build system or dependencies
|
|
511
|
+
ci: CI configuration
|
|
512
|
+
chore: Maintenance tasks
|
|
513
|
+
revert: Revert a previous commit
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
### Breaking Changes
|
|
517
|
+
|
|
518
|
+
```
|
|
519
|
+
feat(api)!: remove deprecated endpoints
|
|
520
|
+
|
|
521
|
+
BREAKING CHANGE: The /v1/users endpoint has been removed.
|
|
522
|
+
Use /v2/users instead.
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
### Examples
|
|
526
|
+
|
|
527
|
+
```
|
|
528
|
+
feat(auth): add OAuth2 login with Google
|
|
529
|
+
fix(parser): handle nested quotes in CSV import
|
|
530
|
+
docs(api): add rate limiting section to API docs
|
|
531
|
+
refactor(db): extract connection pool into separate module
|
|
532
|
+
perf(search): add index on created_at column
|
|
533
|
+
test(auth): add integration tests for token refresh
|
|
534
|
+
build: upgrade TypeScript to 5.4
|
|
535
|
+
ci: add Node 22 to test matrix
|
|
536
|
+
chore: remove unused dependencies
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
---
|
|
540
|
+
|
|
541
|
+
## 10. Merge Strategies
|
|
542
|
+
|
|
543
|
+
### Fast-Forward Only
|
|
544
|
+
|
|
545
|
+
```bash
|
|
546
|
+
# Only merge if it can be a fast-forward (linear history)
|
|
547
|
+
git merge --ff-only feature
|
|
548
|
+
|
|
549
|
+
# Fail if feature has diverged from main
|
|
550
|
+
# Configure as default
|
|
551
|
+
git config --global merge.ff only
|
|
552
|
+
|
|
553
|
+
# Per-branch configuration
|
|
554
|
+
git config branch.main.mergeoptions "--ff-only"
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
### Merge Commits (No Fast-Forward)
|
|
558
|
+
|
|
559
|
+
```bash
|
|
560
|
+
# Always create a merge commit (even if fast-forward is possible)
|
|
561
|
+
git merge --no-ff feature
|
|
562
|
+
|
|
563
|
+
# Preserves branch topology in history
|
|
564
|
+
# Result: A-B-C---------M (main)
|
|
565
|
+
# \ /
|
|
566
|
+
# D-E-F-G (feature)
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
### Squash Merge
|
|
570
|
+
|
|
571
|
+
```bash
|
|
572
|
+
# Squash all feature commits into one commit on main
|
|
573
|
+
git merge --squash feature
|
|
574
|
+
git commit -m "feat(users): add user management module"
|
|
575
|
+
|
|
576
|
+
# Result: A-B-C-S (main, S contains all changes from feature)
|
|
577
|
+
# The feature branch history is lost in main
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
### When to Use Each
|
|
581
|
+
|
|
582
|
+
```
|
|
583
|
+
Fast-forward:
|
|
584
|
+
- Simple, linear changes
|
|
585
|
+
- Single-commit features
|
|
586
|
+
- Hotfixes to release branches
|
|
587
|
+
|
|
588
|
+
Merge commit:
|
|
589
|
+
- Feature branches with multiple meaningful commits
|
|
590
|
+
- When branch history is valuable
|
|
591
|
+
- Team workflows where branch topology matters
|
|
592
|
+
|
|
593
|
+
Squash merge:
|
|
594
|
+
- Feature branches with messy WIP commits
|
|
595
|
+
- When only the final result matters
|
|
596
|
+
- PRs where individual commits are not meaningful
|
|
597
|
+
```
|
|
598
|
+
|
|
599
|
+
---
|
|
600
|
+
|
|
601
|
+
## 11. Branch Naming Conventions
|
|
602
|
+
|
|
603
|
+
```
|
|
604
|
+
# Pattern: <type>/<ticket>-<description>
|
|
605
|
+
|
|
606
|
+
feature/AUTH-123-oauth-login
|
|
607
|
+
bugfix/BUG-456-fix-null-pointer
|
|
608
|
+
hotfix/HOT-789-security-patch
|
|
609
|
+
chore/CHORE-012-update-deps
|
|
610
|
+
docs/DOCS-345-api-reference
|
|
611
|
+
release/v2.1.0
|
|
612
|
+
experiment/try-new-parser
|
|
613
|
+
|
|
614
|
+
# Short-lived branches:
|
|
615
|
+
# - feature/* -- merged and deleted
|
|
616
|
+
# - bugfix/* -- merged and deleted
|
|
617
|
+
# - hotfix/* -- merged and deleted
|
|
618
|
+
|
|
619
|
+
# Long-lived branches:
|
|
620
|
+
# - main (or master) -- production
|
|
621
|
+
# - develop -- integration (if using gitflow)
|
|
622
|
+
# - release/* -- release candidates
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
---
|
|
626
|
+
|
|
627
|
+
## 12. Git Attributes
|
|
628
|
+
|
|
629
|
+
### LFS (Large File Storage)
|
|
630
|
+
|
|
631
|
+
```bash
|
|
632
|
+
# Install Git LFS
|
|
633
|
+
git lfs install
|
|
634
|
+
|
|
635
|
+
# Track file types
|
|
636
|
+
git lfs track "*.psd"
|
|
637
|
+
git lfs track "*.zip"
|
|
638
|
+
git lfs track "*.mp4"
|
|
639
|
+
git lfs track "assets/textures/**"
|
|
640
|
+
|
|
641
|
+
# This creates/updates .gitattributes:
|
|
642
|
+
# *.psd filter=lfs diff=lfs merge=lfs -text
|
|
643
|
+
# *.zip filter=lfs diff=lfs merge=lfs -text
|
|
644
|
+
|
|
645
|
+
# Commit .gitattributes first
|
|
646
|
+
git add .gitattributes
|
|
647
|
+
git commit -m "chore: configure Git LFS for binary assets"
|
|
648
|
+
|
|
649
|
+
# Then add and commit large files normally
|
|
650
|
+
git add assets/hero.psd
|
|
651
|
+
git commit -m "feat(assets): add hero character artwork"
|
|
652
|
+
|
|
653
|
+
# Check LFS status
|
|
654
|
+
git lfs ls-files
|
|
655
|
+
git lfs status
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
### Custom Diff Drivers
|
|
659
|
+
|
|
660
|
+
```gitattributes
|
|
661
|
+
# .gitattributes
|
|
662
|
+
|
|
663
|
+
# Treat these as binary (no diff)
|
|
664
|
+
*.png binary
|
|
665
|
+
*.jpg binary
|
|
666
|
+
|
|
667
|
+
# Use custom diff for lock files
|
|
668
|
+
package-lock.json diff=lockfile
|
|
669
|
+
yarn.lock diff=lockfile
|
|
670
|
+
|
|
671
|
+
# Normalize line endings
|
|
672
|
+
*.ts text eol=lf
|
|
673
|
+
*.tsx text eol=lf
|
|
674
|
+
*.json text eol=lf
|
|
675
|
+
*.md text eol=lf
|
|
676
|
+
*.sh text eol=lf
|
|
677
|
+
*.bat text eol=crlf
|
|
678
|
+
|
|
679
|
+
# Export-ignore (excluded from archives)
|
|
680
|
+
.github/ export-ignore
|
|
681
|
+
tests/ export-ignore
|
|
682
|
+
docs/ export-ignore
|
|
683
|
+
.gitattributes export-ignore
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
---
|
|
687
|
+
|
|
688
|
+
## 13. Blame and Log Archaeology
|
|
689
|
+
|
|
690
|
+
```bash
|
|
691
|
+
# Blame: show who last modified each line
|
|
692
|
+
git blame src/auth.ts
|
|
693
|
+
|
|
694
|
+
# Blame with line range
|
|
695
|
+
git blame -L 10,30 src/auth.ts
|
|
696
|
+
|
|
697
|
+
# Ignore whitespace changes in blame
|
|
698
|
+
git blame -w src/auth.ts
|
|
699
|
+
|
|
700
|
+
# Show blame before a specific commit (skip past a refactor)
|
|
701
|
+
git blame --ignore-rev abc1234 src/auth.ts
|
|
702
|
+
|
|
703
|
+
# Ignore bulk reformatting commits (create a file listing them)
|
|
704
|
+
echo "abc1234" >> .git-blame-ignore-revs
|
|
705
|
+
echo "def5678" >> .git-blame-ignore-revs
|
|
706
|
+
git config blame.ignoreRevsFile .git-blame-ignore-revs
|
|
707
|
+
|
|
708
|
+
# Log: search commit messages
|
|
709
|
+
git log --grep="fix.*auth" --oneline
|
|
710
|
+
|
|
711
|
+
# Log: search code changes (pickaxe -- find when a string was added/removed)
|
|
712
|
+
git log -S "function authenticate" --oneline
|
|
713
|
+
|
|
714
|
+
# Log: search code changes with regex
|
|
715
|
+
git log -G "authenticate\(" --oneline
|
|
716
|
+
|
|
717
|
+
# Log: show file history
|
|
718
|
+
git log --follow -p -- src/auth.ts
|
|
719
|
+
|
|
720
|
+
# Log: show changes between two dates
|
|
721
|
+
git log --after="2025-01-01" --before="2025-02-01" --oneline
|
|
722
|
+
|
|
723
|
+
# Log: show commits by author
|
|
724
|
+
git log --author="jane" --oneline
|
|
725
|
+
|
|
726
|
+
# Log: show a graph of branch history
|
|
727
|
+
git log --oneline --graph --all --decorate
|
|
728
|
+
|
|
729
|
+
# Show when a file was deleted
|
|
730
|
+
git log --diff-filter=D -- src/old-file.ts
|
|
731
|
+
|
|
732
|
+
# Show who has contributed the most lines to a file
|
|
733
|
+
git shortlog -sn -- src/auth.ts
|
|
734
|
+
```
|
|
735
|
+
|
|
736
|
+
---
|
|
737
|
+
|
|
738
|
+
## 14. Patch Workflow
|
|
739
|
+
|
|
740
|
+
```bash
|
|
741
|
+
# Create a patch file from the last commit
|
|
742
|
+
git format-patch -1 HEAD
|
|
743
|
+
|
|
744
|
+
# Create patches for a range of commits
|
|
745
|
+
git format-patch main..feature
|
|
746
|
+
|
|
747
|
+
# Create a single combined patch
|
|
748
|
+
git format-patch main..feature --stdout > combined.patch
|
|
749
|
+
|
|
750
|
+
# Apply a patch (creates commits)
|
|
751
|
+
git am 0001-feat-add-user-model.patch
|
|
752
|
+
|
|
753
|
+
# Apply a patch (without committing)
|
|
754
|
+
git apply feature.patch
|
|
755
|
+
|
|
756
|
+
# Check if a patch applies cleanly
|
|
757
|
+
git apply --check feature.patch
|
|
758
|
+
|
|
759
|
+
# Apply with 3-way merge (better conflict handling)
|
|
760
|
+
git am -3 0001-feat-add-user-model.patch
|
|
761
|
+
|
|
762
|
+
# Send patches via email (traditional open source workflow)
|
|
763
|
+
git send-email --to=maintainer@example.com 0001-feat-add-user-model.patch
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
---
|
|
767
|
+
|
|
768
|
+
## 15. Sparse Checkout
|
|
769
|
+
|
|
770
|
+
```bash
|
|
771
|
+
# Initialize sparse checkout
|
|
772
|
+
git clone --no-checkout https://github.com/user/monorepo.git
|
|
773
|
+
cd monorepo
|
|
774
|
+
git sparse-checkout init --cone
|
|
775
|
+
|
|
776
|
+
# Check out only specific directories
|
|
777
|
+
git sparse-checkout set packages/auth packages/shared
|
|
778
|
+
|
|
779
|
+
# Add more directories later
|
|
780
|
+
git sparse-checkout add packages/api
|
|
781
|
+
|
|
782
|
+
# List current sparse checkout paths
|
|
783
|
+
git sparse-checkout list
|
|
784
|
+
|
|
785
|
+
# Disable sparse checkout (get everything)
|
|
786
|
+
git sparse-checkout disable
|
|
787
|
+
|
|
788
|
+
# Non-cone mode (pattern-based)
|
|
789
|
+
git sparse-checkout init
|
|
790
|
+
git sparse-checkout set '*.md' 'docs/**' 'src/core/**'
|
|
791
|
+
```
|
|
792
|
+
|
|
793
|
+
---
|
|
794
|
+
|
|
795
|
+
## 16. filter-repo (Rewriting History)
|
|
796
|
+
|
|
797
|
+
```bash
|
|
798
|
+
# Install: pip install git-filter-repo
|
|
799
|
+
|
|
800
|
+
# Remove a file from entire history (e.g., accidentally committed secret)
|
|
801
|
+
git filter-repo --invert-paths --path secrets.env
|
|
802
|
+
|
|
803
|
+
# Remove a directory from entire history
|
|
804
|
+
git filter-repo --invert-paths --path vendor/
|
|
805
|
+
|
|
806
|
+
# Move all files into a subdirectory (preparing for monorepo merge)
|
|
807
|
+
git filter-repo --to-subdirectory-filter packages/auth
|
|
808
|
+
|
|
809
|
+
# Replace text in all files across history
|
|
810
|
+
git filter-repo --replace-text expressions.txt
|
|
811
|
+
# expressions.txt:
|
|
812
|
+
# old-api-key==>REDACTED
|
|
813
|
+
# secret-password==>REDACTED
|
|
814
|
+
|
|
815
|
+
# Filter by file size (remove files larger than 10MB)
|
|
816
|
+
git filter-repo --strip-blobs-bigger-than 10M
|
|
817
|
+
|
|
818
|
+
# WARNING: filter-repo rewrites ALL commit hashes.
|
|
819
|
+
# Force push is required after running it.
|
|
820
|
+
# Coordinate with all team members before using.
|
|
821
|
+
```
|
|
822
|
+
|
|
823
|
+
---
|
|
824
|
+
|
|
825
|
+
## 17. Signing Commits
|
|
826
|
+
|
|
827
|
+
### GPG Signing
|
|
828
|
+
|
|
829
|
+
```bash
|
|
830
|
+
# Generate a GPG key
|
|
831
|
+
gpg --full-generate-key
|
|
832
|
+
|
|
833
|
+
# List keys
|
|
834
|
+
gpg --list-secret-keys --keyid-format=long
|
|
835
|
+
|
|
836
|
+
# Configure Git to use the key
|
|
837
|
+
git config --global user.signingkey ABCDEF1234567890
|
|
838
|
+
git config --global commit.gpgsign true
|
|
839
|
+
|
|
840
|
+
# Sign a commit
|
|
841
|
+
git commit -S -m "feat: signed commit"
|
|
842
|
+
|
|
843
|
+
# Sign a tag
|
|
844
|
+
git tag -s v1.0.0 -m "Release v1.0.0"
|
|
845
|
+
|
|
846
|
+
# Verify a commit signature
|
|
847
|
+
git verify-commit HEAD
|
|
848
|
+
|
|
849
|
+
# Verify a tag signature
|
|
850
|
+
git verify-tag v1.0.0
|
|
851
|
+
|
|
852
|
+
# Show signatures in log
|
|
853
|
+
git log --show-signature
|
|
854
|
+
```
|
|
855
|
+
|
|
856
|
+
### SSH Signing (Simpler, Recommended for GitHub)
|
|
857
|
+
|
|
858
|
+
```bash
|
|
859
|
+
# Configure SSH signing
|
|
860
|
+
git config --global gpg.format ssh
|
|
861
|
+
git config --global user.signingkey ~/.ssh/id_ed25519.pub
|
|
862
|
+
git config --global commit.gpgsign true
|
|
863
|
+
git config --global tag.gpgsign true
|
|
864
|
+
|
|
865
|
+
# Verify SSH signatures
|
|
866
|
+
git config --global gpg.ssh.allowedSignersFile ~/.ssh/allowed_signers
|
|
867
|
+
|
|
868
|
+
# Create allowed_signers file
|
|
869
|
+
echo "user@example.com ssh-ed25519 AAAA..." > ~/.ssh/allowed_signers
|
|
870
|
+
```
|
|
871
|
+
|
|
872
|
+
---
|
|
873
|
+
|
|
874
|
+
## 18. Performance Optimizations
|
|
875
|
+
|
|
876
|
+
### Partial Clone
|
|
877
|
+
|
|
878
|
+
```bash
|
|
879
|
+
# Clone without blob data (download on demand)
|
|
880
|
+
git clone --filter=blob:none https://github.com/user/large-repo.git
|
|
881
|
+
|
|
882
|
+
# Clone without trees and blobs (blobless + treeless)
|
|
883
|
+
git clone --filter=tree:0 https://github.com/user/huge-repo.git
|
|
884
|
+
|
|
885
|
+
# Blobs are fetched on checkout/diff as needed
|
|
886
|
+
# Dramatically reduces clone time for large repos
|
|
887
|
+
```
|
|
888
|
+
|
|
889
|
+
### Shallow Clone
|
|
890
|
+
|
|
891
|
+
```bash
|
|
892
|
+
# Clone with limited history depth
|
|
893
|
+
git clone --depth=1 https://github.com/user/repo.git
|
|
894
|
+
|
|
895
|
+
# Fetch more history later
|
|
896
|
+
git fetch --deepen=50
|
|
897
|
+
|
|
898
|
+
# Convert to full clone
|
|
899
|
+
git fetch --unshallow
|
|
900
|
+
```
|
|
901
|
+
|
|
902
|
+
### Commit Graph
|
|
903
|
+
|
|
904
|
+
```bash
|
|
905
|
+
# Generate a commit-graph file (speeds up log, merge-base, etc.)
|
|
906
|
+
git commit-graph write --reachable
|
|
907
|
+
|
|
908
|
+
# Enable automatic maintenance
|
|
909
|
+
git config --global fetch.writeCommitGraph true
|
|
910
|
+
git maintenance start
|
|
911
|
+
|
|
912
|
+
# The commit graph caches commit metadata for O(1) lookups
|
|
913
|
+
# instead of O(n) traversal through pack files
|
|
914
|
+
```
|
|
915
|
+
|
|
916
|
+
### File System Monitor
|
|
917
|
+
|
|
918
|
+
```bash
|
|
919
|
+
# Enable FSMonitor (watches for file changes, speeds up status/diff)
|
|
920
|
+
git config core.fsmonitor true
|
|
921
|
+
git config core.untrackedCache true
|
|
922
|
+
|
|
923
|
+
# On macOS: uses FSEvents
|
|
924
|
+
# On Linux: uses inotify or Watchman
|
|
925
|
+
# On Windows: uses ReadDirectoryChangesW
|
|
926
|
+
|
|
927
|
+
# For very large repos, install Watchman:
|
|
928
|
+
# brew install watchman (macOS)
|
|
929
|
+
# Then: git config core.fsmonitor "$(which watchman)"
|
|
930
|
+
```
|
|
931
|
+
|
|
932
|
+
### Maintenance
|
|
933
|
+
|
|
934
|
+
```bash
|
|
935
|
+
# Run scheduled maintenance (gc, commit-graph, prefetch)
|
|
936
|
+
git maintenance start
|
|
937
|
+
|
|
938
|
+
# Manual maintenance
|
|
939
|
+
git maintenance run --task=gc
|
|
940
|
+
git maintenance run --task=commit-graph
|
|
941
|
+
git maintenance run --task=loose-objects
|
|
942
|
+
|
|
943
|
+
# Configure maintenance schedule
|
|
944
|
+
git maintenance register
|
|
945
|
+
```
|
|
946
|
+
|
|
947
|
+
---
|
|
948
|
+
|
|
949
|
+
## 19. Anti-Patterns
|
|
950
|
+
|
|
951
|
+
### NEVER
|
|
952
|
+
|
|
953
|
+
- Force push to main/master without team coordination
|
|
954
|
+
- Use `git push --force` (use `--force-with-lease` instead -- it checks for upstream changes)
|
|
955
|
+
- Commit secrets, credentials, or API keys (use `.gitignore` and git-secrets)
|
|
956
|
+
- Rebase commits that have been pushed and shared with others
|
|
957
|
+
- Use `git clean -fd` without checking `git clean -nd` first (dry run)
|
|
958
|
+
- Use `git reset --hard` without checking `git reflog` first
|
|
959
|
+
- Commit generated files (build output, node_modules, .env)
|
|
960
|
+
- Use merge commits for single-commit changes (use fast-forward)
|
|
961
|
+
|
|
962
|
+
### ALWAYS
|
|
963
|
+
|
|
964
|
+
- Write meaningful commit messages (describe WHY, not just WHAT)
|
|
965
|
+
- Use `--force-with-lease` instead of `--force` for push
|
|
966
|
+
- Check `git status` and `git diff` before committing
|
|
967
|
+
- Use `.gitignore` for build artifacts, dependencies, and IDE files
|
|
968
|
+
- Back up before destructive operations (reflog is your safety net)
|
|
969
|
+
- Use signed commits for production-critical repositories
|
|
970
|
+
- Configure line ending normalization in `.gitattributes`
|
|
971
|
+
- Use partial/sparse clone for large monorepos in CI
|
|
972
|
+
- Run `git maintenance` on repositories you work with frequently
|