@sylix/coworker 2.0.11 → 2.0.12

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.
Files changed (169) hide show
  1. package/dist/commands/slash/config.d.ts.map +1 -1
  2. package/dist/commands/slash/config.js +22 -4
  3. package/dist/commands/slash/config.js.map +1 -1
  4. package/dist/core/CoWorkerAgent.d.ts.map +1 -1
  5. package/dist/core/CoWorkerAgent.js +6 -3
  6. package/dist/core/CoWorkerAgent.js.map +1 -1
  7. package/dist/skills/defaults/accessibility/screen-reader-testing.md +545 -0
  8. package/dist/skills/defaults/accessibility/wcag-audit-patterns.md +555 -0
  9. package/dist/skills/defaults/ai-ml/rag.md +276 -0
  10. package/dist/skills/defaults/backend-development/api-design-principles.md +528 -0
  11. package/dist/skills/defaults/backend-development/api-design.md +285 -0
  12. package/dist/skills/defaults/backend-development/architecture-patterns.md +494 -0
  13. package/dist/skills/defaults/backend-development/async-python.md +237 -0
  14. package/dist/skills/defaults/backend-development/auth-implementation-patterns.md +638 -0
  15. package/dist/skills/defaults/backend-development/bazel-build-optimization.md +387 -0
  16. package/dist/skills/defaults/backend-development/billing-automation/SKILL.md +566 -0
  17. package/dist/skills/defaults/backend-development/code-review-excellence.md +538 -0
  18. package/dist/skills/defaults/backend-development/cqrs-implementation.md +554 -0
  19. package/dist/skills/defaults/backend-development/database-design.md +305 -0
  20. package/dist/skills/defaults/backend-development/debugging-strategies.md +536 -0
  21. package/dist/skills/defaults/backend-development/e2e-testing-patterns.md +544 -0
  22. package/dist/skills/defaults/backend-development/error-handling-patterns.md +641 -0
  23. package/dist/skills/defaults/backend-development/fastapi-templates.md +559 -0
  24. package/dist/skills/defaults/backend-development/fastapi.md +309 -0
  25. package/dist/skills/defaults/backend-development/git-advanced-workflows.md +405 -0
  26. package/dist/skills/defaults/backend-development/microservices-patterns.md +595 -0
  27. package/dist/skills/defaults/backend-development/microservices.md +284 -0
  28. package/dist/skills/defaults/backend-development/monorepo-management.md +623 -0
  29. package/dist/skills/defaults/backend-development/nodejs-backend-patterns.md +1048 -0
  30. package/dist/skills/defaults/backend-development/nx-workspace-patterns.md +457 -0
  31. package/dist/skills/defaults/backend-development/paypal-integration/SKILL.md +478 -0
  32. package/dist/skills/defaults/backend-development/pci-compliance/SKILL.md +480 -0
  33. package/dist/skills/defaults/backend-development/python-anti-patterns.md +349 -0
  34. package/dist/skills/defaults/backend-development/python-background-jobs.md +364 -0
  35. package/dist/skills/defaults/backend-development/python-code-style.md +360 -0
  36. package/dist/skills/defaults/backend-development/python-configuration.md +368 -0
  37. package/dist/skills/defaults/backend-development/python-design-patterns.md +296 -0
  38. package/dist/skills/defaults/backend-development/python-error-handling.md +323 -0
  39. package/dist/skills/defaults/backend-development/python-packaging.md +887 -0
  40. package/dist/skills/defaults/backend-development/python-performance-optimization.md +874 -0
  41. package/dist/skills/defaults/backend-development/python-project-structure.md +252 -0
  42. package/dist/skills/defaults/backend-development/python-resilience.md +376 -0
  43. package/dist/skills/defaults/backend-development/python-resource-management.md +421 -0
  44. package/dist/skills/defaults/backend-development/python-type-safety.md +428 -0
  45. package/dist/skills/defaults/backend-development/sql-optimization-patterns.md +509 -0
  46. package/dist/skills/defaults/backend-development/stripe-integration/SKILL.md +522 -0
  47. package/dist/skills/defaults/backend-development/turborepo-caching.md +376 -0
  48. package/dist/skills/defaults/blockchain/defi-protocol-templates.md +430 -0
  49. package/dist/skills/defaults/blockchain/nft-standards.md +364 -0
  50. package/dist/skills/defaults/blockchain/solidity-security.md +514 -0
  51. package/dist/skills/defaults/blockchain/web3-testing.md +360 -0
  52. package/dist/skills/defaults/business/competitive-landscape/SKILL.md +527 -0
  53. package/dist/skills/defaults/business/market-sizing-analysis/SKILL.md +451 -0
  54. package/dist/skills/defaults/business/startup-financial-modeling/SKILL.md +494 -0
  55. package/dist/skills/defaults/business/startup-metrics-framework/SKILL.md +564 -0
  56. package/dist/skills/defaults/business/team-composition-analysis.md +437 -0
  57. package/dist/skills/defaults/compliance/employment-contract-templates/SKILL.md +527 -0
  58. package/dist/skills/defaults/compliance/gdpr-data-handling/SKILL.md +630 -0
  59. package/dist/skills/defaults/data-engineering/airflow-dag-patterns.md +436 -0
  60. package/dist/skills/defaults/data-engineering/airflow.md +519 -0
  61. package/dist/skills/defaults/data-engineering/data-quality.md +583 -0
  62. package/dist/skills/defaults/data-engineering/dbt-transformation-patterns.md +482 -0
  63. package/dist/skills/defaults/data-engineering/dbt.md +556 -0
  64. package/dist/skills/defaults/data-engineering/ml-pipeline-workflow/SKILL.md +247 -0
  65. package/dist/skills/defaults/data-engineering/spark-optimization.md +348 -0
  66. package/dist/skills/defaults/data-engineering/spark.md +411 -0
  67. package/dist/skills/defaults/database/postgresql.md +202 -0
  68. package/dist/skills/defaults/debugging/systematic-debugging.md +249 -0
  69. package/dist/skills/defaults/devops/architecture-decision-records.md +448 -0
  70. package/dist/skills/defaults/devops/changelog-automation.md +580 -0
  71. package/dist/skills/defaults/devops/cicd.md +314 -0
  72. package/dist/skills/defaults/devops/cloud.md +263 -0
  73. package/dist/skills/defaults/devops/code-review-excellence.md +299 -0
  74. package/dist/skills/defaults/devops/cost-optimization.md +295 -0
  75. package/dist/skills/defaults/devops/deployment-pipeline-design.md +356 -0
  76. package/dist/skills/defaults/devops/docker.md +281 -0
  77. package/dist/skills/defaults/devops/git-workflows.md +205 -0
  78. package/dist/skills/defaults/devops/github-actions.md +311 -0
  79. package/dist/skills/defaults/devops/gitlab-ci-patterns.md +266 -0
  80. package/dist/skills/defaults/devops/hybrid-cloud-networking.md +241 -0
  81. package/dist/skills/defaults/devops/istio-traffic-management.md +327 -0
  82. package/dist/skills/defaults/devops/kubernetes.md +339 -0
  83. package/dist/skills/defaults/devops/linkerd-patterns.md +311 -0
  84. package/dist/skills/defaults/devops/multi-cloud-architecture.md +181 -0
  85. package/dist/skills/defaults/devops/observability.md +243 -0
  86. package/dist/skills/defaults/devops/openapi-spec-generation.md +1024 -0
  87. package/dist/skills/defaults/devops/postmortem-writing.md +396 -0
  88. package/dist/skills/defaults/devops/prometheus-configuration.md +265 -0
  89. package/dist/skills/defaults/devops/secrets-management.md +341 -0
  90. package/dist/skills/defaults/devops/service-mesh-observability.md +385 -0
  91. package/dist/skills/defaults/devops/terraform-module-library.md +244 -0
  92. package/dist/skills/defaults/finance/backtesting-frameworks/SKILL.md +663 -0
  93. package/dist/skills/defaults/finance/risk-metrics-calculation/SKILL.md +557 -0
  94. package/dist/skills/defaults/frontend/accessibility-compliance.md +420 -0
  95. package/dist/skills/defaults/frontend/design-system-patterns.md +337 -0
  96. package/dist/skills/defaults/frontend/interaction-design.md +327 -0
  97. package/dist/skills/defaults/frontend/javascript.md +311 -0
  98. package/dist/skills/defaults/frontend/modern-javascript-patterns.md +927 -0
  99. package/dist/skills/defaults/frontend/react-native-design.md +440 -0
  100. package/dist/skills/defaults/frontend/react.md +345 -0
  101. package/dist/skills/defaults/frontend/responsive-design.md +472 -0
  102. package/dist/skills/defaults/frontend/tailwind-design-system.md +337 -0
  103. package/dist/skills/defaults/frontend/typescript-advanced-types.md +724 -0
  104. package/dist/skills/defaults/frontend/typescript.md +334 -0
  105. package/dist/skills/defaults/frontend/visual-design-foundations.md +326 -0
  106. package/dist/skills/defaults/frontend/web-component-design.md +279 -0
  107. package/dist/skills/defaults/game-development/godot-gdscript-patterns.md +188 -0
  108. package/dist/skills/defaults/game-development/unity-ecs-patterns.md +594 -0
  109. package/dist/skills/defaults/kubernetes/gitops-workflow.md +285 -0
  110. package/dist/skills/defaults/kubernetes/gitops.md +280 -0
  111. package/dist/skills/defaults/kubernetes/helm-chart-scaffolding.md +553 -0
  112. package/dist/skills/defaults/kubernetes/helm.md +343 -0
  113. package/dist/skills/defaults/kubernetes/k8s-manifest-generator.md +501 -0
  114. package/dist/skills/defaults/kubernetes/k8s-security-policies.md +342 -0
  115. package/dist/skills/defaults/kubernetes/manifests.md +330 -0
  116. package/dist/skills/defaults/kubernetes/security.md +337 -0
  117. package/dist/skills/defaults/llm-application/embedding-strategies.md +608 -0
  118. package/dist/skills/defaults/llm-application/hybrid-search-implementation.md +570 -0
  119. package/dist/skills/defaults/llm-application/hybrid-search.md +570 -0
  120. package/dist/skills/defaults/llm-application/langchain-architecture.md +666 -0
  121. package/dist/skills/defaults/llm-application/langchain.md +259 -0
  122. package/dist/skills/defaults/llm-application/llm-evaluation.md +695 -0
  123. package/dist/skills/defaults/llm-application/prompt-engineering-patterns.md +449 -0
  124. package/dist/skills/defaults/llm-application/prompt-engineering.md +219 -0
  125. package/dist/skills/defaults/llm-application/rag-implementation.md +434 -0
  126. package/dist/skills/defaults/llm-application/similarity-search-patterns.md +560 -0
  127. package/dist/skills/defaults/llm-application/similarity-search.md +560 -0
  128. package/dist/skills/defaults/llm-application/vector-index-tuning.md +523 -0
  129. package/dist/skills/defaults/mobile/mobile-android-design.md +440 -0
  130. package/dist/skills/defaults/mobile/mobile-ios-design.md +266 -0
  131. package/dist/skills/defaults/monitoring/distributed-tracing.md +436 -0
  132. package/dist/skills/defaults/monitoring/grafana-dashboards.md +370 -0
  133. package/dist/skills/defaults/monitoring/prometheus-configuration.md +379 -0
  134. package/dist/skills/defaults/monitoring/slo-implementation.md +323 -0
  135. package/dist/skills/defaults/refactoring/code-refactoring.md +349 -0
  136. package/dist/skills/defaults/security/anti-reversing-techniques/SKILL.md +559 -0
  137. package/dist/skills/defaults/security/auditor.md +168 -0
  138. package/dist/skills/defaults/security/binary-analysis-patterns/SKILL.md +438 -0
  139. package/dist/skills/defaults/security/memory-forensics/SKILL.md +483 -0
  140. package/dist/skills/defaults/security/mtls-configuration.md +349 -0
  141. package/dist/skills/defaults/security/protocol-reverse-engineering/SKILL.md +520 -0
  142. package/dist/skills/defaults/security/sast-configuration.md +182 -0
  143. package/dist/skills/defaults/security/security.md +313 -0
  144. package/dist/skills/defaults/security/stride-analysis.md +273 -0
  145. package/dist/skills/defaults/security/threat-mitigation-mapping.md +290 -0
  146. package/dist/skills/defaults/systems/bash-defensive-patterns/SKILL.md +539 -0
  147. package/dist/skills/defaults/systems/bats-testing-patterns/SKILL.md +631 -0
  148. package/dist/skills/defaults/systems/go-concurrency-patterns.md +657 -0
  149. package/dist/skills/defaults/systems/memory-safety-patterns.md +605 -0
  150. package/dist/skills/defaults/systems/rust-async-patterns.md +519 -0
  151. package/dist/skills/defaults/systems/shellcheck-configuration/SKILL.md +456 -0
  152. package/dist/skills/defaults/team-collaboration/multi-reviewer-patterns.md +126 -0
  153. package/dist/skills/defaults/team-collaboration/parallel-feature-development.md +151 -0
  154. package/dist/skills/defaults/testing/javascript-testing-patterns.md +1021 -0
  155. package/dist/skills/defaults/testing/python-testing-patterns.md +351 -0
  156. package/dist/skills/defaults/testing/testing.md +332 -0
  157. package/dist/skills/defaults/workflows/context-driven-development.md +384 -0
  158. package/dist/skills/defaults/workflows/track-management.md +592 -0
  159. package/dist/skills/defaults/workflows/workflow-patterns.md +622 -0
  160. package/dist/skills/index.d.ts +11 -0
  161. package/dist/skills/index.d.ts.map +1 -0
  162. package/dist/skills/index.js +129 -0
  163. package/dist/skills/index.js.map +1 -0
  164. package/dist/utils/character.js +4 -4
  165. package/dist/utils/character.js.map +1 -1
  166. package/dist/utils/inputbar.d.ts.map +1 -1
  167. package/dist/utils/inputbar.js +7 -0
  168. package/dist/utils/inputbar.js.map +1 -1
  169. package/package.json +1 -1
@@ -0,0 +1,309 @@
1
+ ---
2
+ name: fastapi
3
+ description: Build high-performance APIs with FastAPI, including dependency injection, middleware, and async patterns.
4
+ ---
5
+
6
+ # FastAPI — CoWorker Edition
7
+
8
+ Build fast, modern Python APIs.
9
+
10
+ ## When to Use This Skill
11
+
12
+ - Building REST APIs
13
+ - Async Python services
14
+ - OpenAPI documentation
15
+ - Data validation
16
+
17
+ ## Core Concepts
18
+
19
+ ### 1. Basic API
20
+
21
+ ```python
22
+ from fastapi import FastAPI, HTTPException
23
+ from pydantic import BaseModel, EmailStr
24
+ from typing import Optional
25
+ from datetime import datetime
26
+
27
+ app = FastAPI(
28
+ title="My API",
29
+ version="1.0.0",
30
+ docs_url="/docs",
31
+ redoc_url="/redoc"
32
+ )
33
+
34
+ class UserCreate(BaseModel):
35
+ email: EmailStr
36
+ name: str
37
+ age: Optional[int] = None
38
+
39
+ class User(BaseModel):
40
+ id: int
41
+ email: EmailStr
42
+ name: str
43
+ created_at: datetime
44
+
45
+ class Config:
46
+ from_attributes = True
47
+
48
+ @app.post("/users", response_model=User, status_code=201)
49
+ async def create_user(user: UserCreate):
50
+ # Validate and save
51
+ db_user = await save_user(user)
52
+ return db_user
53
+
54
+ @app.get("/users/{user_id}", response_model=User)
55
+ async def get_user(user_id: int):
56
+ user = await fetch_user(user_id)
57
+ if not user:
58
+ raise HTTPException(404, "User not found")
59
+ return user
60
+ ```
61
+
62
+ ### 2. Dependency Injection
63
+
64
+ ```python
65
+ from fastapi import Depends, Header
66
+ from asyncpg import Pool
67
+ import redis
68
+
69
+ # Database dependency
70
+ async def get_db() -> Pool:
71
+ async with db_pool.acquire() as conn:
72
+ yield conn
73
+
74
+ # Cache dependency
75
+ async def get_cache() -> redis.Redis:
76
+ return redis_client
77
+
78
+ # Auth dependency
79
+ async def get_current_user(
80
+ authorization: str = Header(...),
81
+ db: Pool = Depends(get_db)
82
+ ):
83
+ token = authorization.replace("Bearer ", "")
84
+ user = await verify_token(token, db)
85
+ if not user:
86
+ raise HTTPException(401, "Invalid token")
87
+ return user
88
+
89
+ # Use in endpoint
90
+ @app.get("/protected")
91
+ async def protected_route(
92
+ user: dict = Depends(get_current_user)
93
+ ):
94
+ return {"user": user}
95
+ ```
96
+
97
+ ### 3. Query Parameters
98
+
99
+ ```python
100
+ from fastapi import Query, Path, Body
101
+
102
+ @app.get("/users")
103
+ async def list_users(
104
+ skip: int = Query(0, ge=0),
105
+ limit: int = Query(10, ge=1, le=100),
106
+ search: Optional[str] = Query(None),
107
+ sort: str = Query("created_at", regex="^(name|email|created_at)$")
108
+ ):
109
+ users = await db.fetch(
110
+ """
111
+ SELECT * FROM users
112
+ WHERE ($3 IS NULL OR name ILIKE $3)
113
+ ORDER BY $4
114
+ LIMIT $2 OFFSET $1
115
+ """,
116
+ skip, limit, f"%{search}%" if search else None, sort
117
+ )
118
+ return users
119
+
120
+ @app.get("/items/{item_id}")
121
+ async def get_item(
122
+ item_id: int = Path(..., gt=0),
123
+ include_details: bool = Query(False)
124
+ ):
125
+ item = await fetch_item(item_id)
126
+ if include_details:
127
+ item["details"] = await fetch_details(item_id)
128
+ return item
129
+ ```
130
+
131
+ ### 4. Request Bodies
132
+
133
+ ```python
134
+ from pydantic import BaseModel, Field, validator
135
+
136
+ class ItemCreate(BaseModel):
137
+ name: str = Field(..., min_length=1, max_length=100)
138
+ price: float = Field(..., gt=0)
139
+ quantity: int = Field(default=0, ge=0)
140
+ tags: list[str] = []
141
+
142
+ @validator('tags', pre=True)
143
+ def parse_tags(cls, v):
144
+ if isinstance(v, str):
145
+ return [t.strip() for t in v.split(',')]
146
+ return v
147
+
148
+ class BulkCreate(BaseModel):
149
+ items: list[ItemCreate]
150
+ notify: bool = True
151
+
152
+ @app.post("/items/bulk")
153
+ async def bulk_create(data: Body):
154
+ for item in data.items:
155
+ await save_item(item)
156
+ return {"created": len(data.items)}
157
+ ```
158
+
159
+ ### 5. Error Handling
160
+
161
+ ```python
162
+ from fastapi import Request, status
163
+ from fastapi.responses import JSONResponse
164
+ from fastapi.exceptions import RequestValidationError
165
+
166
+ # Custom exception
167
+ class CustomException(Exception):
168
+ def __init__(self, message: str, code: str):
169
+ self.message = message
170
+ self.code = code
171
+
172
+ app.add_exception_handler(CustomException, custom_exception_handler)
173
+
174
+ async def custom_exception_handler(request: Request, exc: CustomException):
175
+ return JSONResponse(
176
+ status_code=400,
177
+ content={"error": exc.code, "message": exc.message}
178
+ )
179
+
180
+ # Validation error override
181
+ @app.exception_handler(RequestValidationError)
182
+ async def validation_exception_handler(request: Request, exc: RequestValidationError):
183
+ return JSONResponse(
184
+ status_code=422,
185
+ content={"detail": exc.errors()}
186
+ )
187
+ ```
188
+
189
+ ### 6. Middleware
190
+
191
+ ```python
192
+ from fastapi import Request
193
+ from starlette.middleware.base import BaseHTTPMiddleware
194
+ import time
195
+
196
+ # Timing middleware
197
+ class TimingMiddleware(BaseHTTPMiddleware):
198
+ async def dispatch(self, request: Request, call_next):
199
+ start = time.time()
200
+ response = await call_next(request)
201
+ duration = time.time() - start
202
+ response.headers["X-Process-Time"] = str(duration)
203
+ return response
204
+
205
+ app.add_middleware(TimingMiddleware)
206
+
207
+ # CORS
208
+ from fastapi.middleware.cors import CORSMiddleware
209
+
210
+ app.add_middleware(
211
+ CORSMiddleware,
212
+ allow_origins=["https://example.com"],
213
+ allow_credentials=True,
214
+ allow_methods=["*"],
215
+ allow_headers=["*"],
216
+ )
217
+ ```
218
+
219
+ ### 7. WebSocket
220
+
221
+ ```python
222
+ from fastapi import WebSocket, WebSocketDisconnect
223
+
224
+ class ConnectionManager:
225
+ def __init__(self):
226
+ self.active_connections: list[WebSocket] = []
227
+
228
+ async def connect(self, websocket: WebSocket):
229
+ await websocket.accept()
230
+ self.active_connections.append(websocket)
231
+
232
+ def disconnect(self, websocket: WebSocket):
233
+ self.active_connections.remove(websocket)
234
+
235
+ async def broadcast(self, message: dict):
236
+ for connection in self.active_connections:
237
+ await connection.send_json(message)
238
+
239
+ manager = ConnectionManager()
240
+
241
+ @app.websocket("/ws/{client_id}")
242
+ async def websocket_endpoint(websocket: WebSocket, client_id: str):
243
+ await manager.connect(websocket)
244
+ try:
245
+ while True:
246
+ data = await websocket.receive_text()
247
+ await manager.broadcast({
248
+ "sender": client_id,
249
+ "message": data
250
+ })
251
+ except WebSocketDisconnect:
252
+ manager.disconnect(websocket)
253
+ ```
254
+
255
+ ### 8. Background Tasks
256
+
257
+ ```python
258
+ from fastapi import BackgroundTasks
259
+
260
+ def send_email(email: str, subject: str):
261
+ # Email sending logic
262
+ pass
263
+
264
+ @app.post("/users")
265
+ async def create_user(user: UserCreate, background_tasks: BackgroundTasks):
266
+ new_user = await save_user(user)
267
+
268
+ background_tasks.add_task(
269
+ send_email,
270
+ user.email,
271
+ "Welcome!"
272
+ )
273
+
274
+ return new_user
275
+
276
+ # Or with dependency
277
+ async def send_notification(email: str, message: str):
278
+ await email_service.send(email, message)
279
+
280
+ @app.post("/notify")
281
+ async def notify(
282
+ email: str,
283
+ message: str,
284
+ background_tasks: BackgroundTasks,
285
+ email_service: EmailService = Depends(get_email_service)
286
+ ):
287
+ background_tasks.add_task(
288
+ send_notification,
289
+ email,
290
+ message
291
+ )
292
+ return {"status": "queued"}
293
+ ```
294
+
295
+ ## Best Practices
296
+
297
+ 1. **Pydantic models** - Validation everywhere
298
+ 2. **Dependency injection** - Testable
299
+ 3. **Async** - Use for I/O
300
+ 4. **OpenAPI** - Auto-documentation
301
+ 5. **Error handling** - Consistent
302
+
303
+ ## Common Mistakes
304
+
305
+ - Not using Pydantic
306
+ - Sync functions in async routes
307
+ - No error handling
308
+ - Missing validation
309
+ - Not using dependency injection
@@ -0,0 +1,405 @@
1
+ ---
2
+ name: git-advanced-workflows
3
+ description: Master advanced Git workflows including rebasing, cherry-picking, bisect, worktrees, and reflog to maintain clean history and recover from any situation. Use when managing complex Git histories, collaborating on feature branches, or troubleshooting repository issues.
4
+ ---
5
+
6
+ # Git Advanced Workflows
7
+
8
+ Master advanced Git techniques to maintain clean history, collaborate effectively, and recover from any situation with confidence.
9
+
10
+ ## When to Use This Skill
11
+
12
+ - Cleaning up commit history before merging
13
+ - Applying specific commits across branches
14
+ - Finding commits that introduced bugs
15
+ - Working on multiple features simultaneously
16
+ - Recovering from Git mistakes or lost commits
17
+ - Managing complex branch workflows
18
+ - Preparing clean PRs for review
19
+ - Synchronizing diverged branches
20
+
21
+ ## Core Concepts
22
+
23
+ ### 1. Interactive Rebase
24
+
25
+ Interactive rebase is the Swiss Army knife of Git history editing.
26
+
27
+ **Common Operations:**
28
+
29
+ - `pick`: Keep commit as-is
30
+ - `reword`: Change commit message
31
+ - `edit`: Amend commit content
32
+ - `squash`: Combine with previous commit
33
+ - `fixup`: Like squash but discard message
34
+ - `drop`: Remove commit entirely
35
+
36
+ **Basic Usage:**
37
+
38
+ ```bash
39
+ # Rebase last 5 commits
40
+ git rebase -i HEAD~5
41
+
42
+ # Rebase all commits on current branch
43
+ git rebase -i $(git merge-base HEAD main)
44
+
45
+ # Rebase onto specific commit
46
+ git rebase -i abc123
47
+ ```
48
+
49
+ ### 2. Cherry-Picking
50
+
51
+ Apply specific commits from one branch to another without merging entire branches.
52
+
53
+ ```bash
54
+ # Cherry-pick single commit
55
+ git cherry-pick abc123
56
+
57
+ # Cherry-pick range of commits (exclusive start)
58
+ git cherry-pick abc123..def456
59
+
60
+ # Cherry-pick without committing (stage changes only)
61
+ git cherry-pick -n abc123
62
+
63
+ # Cherry-pick and edit commit message
64
+ git cherry-pick -e abc123
65
+ ```
66
+
67
+ ### 3. Git Bisect
68
+
69
+ Binary search through commit history to find the commit that introduced a bug.
70
+
71
+ ```bash
72
+ # Start bisect
73
+ git bisect start
74
+
75
+ # Mark current commit as bad
76
+ git bisect bad
77
+
78
+ # Mark known good commit
79
+ git bisect good v1.0.0
80
+
81
+ # Git will checkout middle commit - test it
82
+ # Then mark as good or bad
83
+ git bisect good # or: git bisect bad
84
+
85
+ # Continue until bug found
86
+ # When done
87
+ git bisect reset
88
+ ```
89
+
90
+ **Automated Bisect:**
91
+
92
+ ```bash
93
+ # Use script to test automatically
94
+ git bisect start HEAD v1.0.0
95
+ git bisect run ./test.sh
96
+
97
+ # test.sh should exit 0 for good, 1-127 (except 125) for bad
98
+ ```
99
+
100
+ ### 4. Worktrees
101
+
102
+ Work on multiple branches simultaneously without stashing or switching.
103
+
104
+ ```bash
105
+ # List existing worktrees
106
+ git worktree list
107
+
108
+ # Add new worktree for feature branch
109
+ git worktree add ../project-feature feature/new-feature
110
+
111
+ # Add worktree and create new branch
112
+ git worktree add -b bugfix/urgent ../project-hotfix main
113
+
114
+ # Remove worktree
115
+ git worktree remove ../project-feature
116
+
117
+ # Prune stale worktrees
118
+ git worktree prune
119
+ ```
120
+
121
+ ### 5. Reflog
122
+
123
+ Your safety net - tracks all ref movements, even deleted commits.
124
+
125
+ ```bash
126
+ # View reflog
127
+ git reflog
128
+
129
+ # View reflog for specific branch
130
+ git reflog show feature/branch
131
+
132
+ # Restore deleted commit
133
+ git reflog
134
+ # Find commit hash
135
+ git checkout abc123
136
+ git branch recovered-branch
137
+
138
+ # Restore deleted branch
139
+ git reflog
140
+ git branch deleted-branch abc123
141
+ ```
142
+
143
+ ## Practical Workflows
144
+
145
+ ### Workflow 1: Clean Up Feature Branch Before PR
146
+
147
+ ```bash
148
+ # Start with feature branch
149
+ git checkout feature/user-auth
150
+
151
+ # Interactive rebase to clean history
152
+ git rebase -i main
153
+
154
+ # Example rebase operations:
155
+ # - Squash "fix typo" commits
156
+ # - Reword commit messages for clarity
157
+ # - Reorder commits logically
158
+ # - Drop unnecessary commits
159
+
160
+ # Force push cleaned branch (safe if no one else is using it)
161
+ git push --force-with-lease origin feature/user-auth
162
+ ```
163
+
164
+ ### Workflow 2: Apply Hotfix to Multiple Releases
165
+
166
+ ```bash
167
+ # Create fix on main
168
+ git checkout main
169
+ git commit -m "fix: critical security patch"
170
+
171
+ # Apply to release branches
172
+ git checkout release/2.0
173
+ git cherry-pick abc123
174
+
175
+ git checkout release/1.9
176
+ git cherry-pick abc123
177
+
178
+ # Handle conflicts if they arise
179
+ git cherry-pick --continue
180
+ # or
181
+ git cherry-pick --abort
182
+ ```
183
+
184
+ ### Workflow 3: Find Bug Introduction
185
+
186
+ ```bash
187
+ # Start bisect
188
+ git bisect start
189
+ git bisect bad HEAD
190
+ git bisect good v2.1.0
191
+
192
+ # Git checks out middle commit - run tests
193
+ npm test
194
+
195
+ # If tests fail
196
+ git bisect bad
197
+
198
+ # If tests pass
199
+ git bisect good
200
+
201
+ # Git will automatically checkout next commit to test
202
+ # Repeat until bug found
203
+
204
+ # Automated version
205
+ git bisect start HEAD v2.1.0
206
+ git bisect run npm test
207
+ ```
208
+
209
+ ### Workflow 4: Multi-Branch Development
210
+
211
+ ```bash
212
+ # Main project directory
213
+ cd ~/projects/myapp
214
+
215
+ # Create worktree for urgent bugfix
216
+ git worktree add ../myapp-hotfix hotfix/critical-bug
217
+
218
+ # Work on hotfix in separate directory
219
+ cd ../myapp-hotfix
220
+ # Make changes, commit
221
+ git commit -m "fix: resolve critical bug"
222
+ git push origin hotfix/critical-bug
223
+
224
+ # Return to main work without interruption
225
+ cd ~/projects/myapp
226
+ git fetch origin
227
+ git cherry-pick hotfix/critical-bug
228
+
229
+ # Clean up when done
230
+ git worktree remove ../myapp-hotfix
231
+ ```
232
+
233
+ ### Workflow 5: Recover from Mistakes
234
+
235
+ ```bash
236
+ # Accidentally reset to wrong commit
237
+ git reset --hard HEAD~5 # Oh no!
238
+
239
+ # Use reflog to find lost commits
240
+ git reflog
241
+ # Output shows:
242
+ # abc123 HEAD@{0}: reset: moving to HEAD~5
243
+ # def456 HEAD@{1}: commit: my important changes
244
+
245
+ # Recover lost commits
246
+ git reset --hard def456
247
+
248
+ # Or create branch from lost commit
249
+ git branch recovery def456
250
+ ```
251
+
252
+ ## Advanced Techniques
253
+
254
+ ### Rebase vs Merge Strategy
255
+
256
+ **When to Rebase:**
257
+
258
+ - Cleaning up local commits before pushing
259
+ - Keeping feature branch up-to-date with main
260
+ - Creating linear history for easier review
261
+
262
+ **When to Merge:**
263
+
264
+ - Integrating completed features into main
265
+ - Preserving exact history of collaboration
266
+ - Public branches used by others
267
+
268
+ ```bash
269
+ # Update feature branch with main changes (rebase)
270
+ git checkout feature/my-feature
271
+ git fetch origin
272
+ git rebase origin/main
273
+
274
+ # Handle conflicts
275
+ git status
276
+ # Fix conflicts in files
277
+ git add .
278
+ git rebase --continue
279
+
280
+ # Or merge instead
281
+ git merge origin/main
282
+ ```
283
+
284
+ ### Autosquash Workflow
285
+
286
+ Automatically squash fixup commits during rebase.
287
+
288
+ ```bash
289
+ # Make initial commit
290
+ git commit -m "feat: add user authentication"
291
+
292
+ # Later, fix something in that commit
293
+ # Stage changes
294
+ git commit --fixup HEAD # or specify commit hash
295
+
296
+ # Make more changes
297
+ git commit --fixup abc123
298
+
299
+ # Rebase with autosquash
300
+ git rebase -i --autosquash main
301
+
302
+ # Git automatically marks fixup commits
303
+ ```
304
+
305
+ ### Split Commit
306
+
307
+ Break one commit into multiple logical commits.
308
+
309
+ ```bash
310
+ # Start interactive rebase
311
+ git rebase -i HEAD~3
312
+
313
+ # Mark commit to split with 'edit'
314
+ # Git will stop at that commit
315
+
316
+ # Reset commit but keep changes
317
+ git reset HEAD^
318
+
319
+ # Stage and commit in logical chunks
320
+ git add file1.py
321
+ git commit -m "feat: add validation"
322
+
323
+ git add file2.py
324
+ git commit -m "feat: add error handling"
325
+
326
+ # Continue rebase
327
+ git rebase --continue
328
+ ```
329
+
330
+ ### Partial Cherry-Pick
331
+
332
+ Cherry-pick only specific files from a commit.
333
+
334
+ ```bash
335
+ # Show files in commit
336
+ git show --name-only abc123
337
+
338
+ # Checkout specific files from commit
339
+ git checkout abc123 -- path/to/file1.py path/to/file2.py
340
+
341
+ # Stage and commit
342
+ git commit -m "cherry-pick: apply specific changes from abc123"
343
+ ```
344
+
345
+ ## Best Practices
346
+
347
+ 1. **Always Use --force-with-lease**: Safer than --force, prevents overwriting others' work
348
+ 2. **Rebase Only Local Commits**: Don't rebase commits that have been pushed and shared
349
+ 3. **Descriptive Commit Messages**: Future you will thank present you
350
+ 4. **Atomic Commits**: Each commit should be a single logical change
351
+ 5. **Test Before Force Push**: Ensure history rewrite didn't break anything
352
+ 6. **Keep Reflog Aware**: Remember reflog is your safety net for 90 days
353
+ 7. **Branch Before Risky Operations**: Create backup branch before complex rebases
354
+
355
+ ```bash
356
+ # Safe force push
357
+ git push --force-with-lease origin feature/branch
358
+
359
+ # Create backup before risky operation
360
+ git branch backup-branch
361
+ git rebase -i main
362
+ # If something goes wrong
363
+ git reset --hard backup-branch
364
+ ```
365
+
366
+ ## Common Pitfalls
367
+
368
+ - **Rebasing Public Branches**: Causes history conflicts for collaborators
369
+ - **Force Pushing Without Lease**: Can overwrite teammate's work
370
+ - **Losing Work in Rebase**: Resolve conflicts carefully, test after rebase
371
+ - **Forgetting Worktree Cleanup**: Orphaned worktrees consume disk space
372
+ - **Not Backing Up Before Experiment**: Always create safety branch
373
+ - **Bisect on Dirty Working Directory**: Commit or stash before bisecting
374
+
375
+ ## Recovery Commands
376
+
377
+ ```bash
378
+ # Abort operations in progress
379
+ git rebase --abort
380
+ git merge --abort
381
+ git cherry-pick --abort
382
+ git bisect reset
383
+
384
+ # Restore file to version from specific commit
385
+ git restore --source=abc123 path/to/file
386
+
387
+ # Undo last commit but keep changes
388
+ git reset --soft HEAD^
389
+
390
+ # Undo last commit and discard changes
391
+ git reset --hard HEAD^
392
+
393
+ # Recover deleted branch (within 90 days)
394
+ git reflog
395
+ git branch recovered-branch abc123
396
+ ```
397
+
398
+ ## Resources
399
+
400
+ - **references/git-rebase-guide.md**: Deep dive into interactive rebase
401
+ - **references/git-conflict-resolution.md**: Advanced conflict resolution strategies
402
+ - **references/git-history-rewriting.md**: Safely rewriting Git history
403
+ - **assets/git-workflow-checklist.md**: Pre-PR cleanup checklist
404
+ - **assets/git-aliases.md**: Useful Git aliases for advanced workflows
405
+ - **scripts/git-clean-branches.sh**: Clean up merged and stale branches