claude-code-templates 1.3.2 → 1.3.4
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 +132 -20
- package/package.json +3 -2
- package/src/command-scanner.js +1 -1
- package/src/file-operations.js +1 -1
- package/src/hook-scanner.js +2 -2
- package/templates/common/.claude/commands/git-workflow.md +239 -0
- package/templates/common/.claude/commands/project-setup.md +316 -0
- package/templates/common/.mcp.json +41 -0
- package/templates/common/CLAUDE.md +109 -0
- package/templates/common/README.md +96 -0
- package/templates/go/.mcp.json +78 -0
- package/templates/go/README.md +25 -0
- package/templates/javascript-typescript/.claude/commands/api-endpoint.md +51 -0
- package/templates/javascript-typescript/.claude/commands/debug.md +52 -0
- package/templates/javascript-typescript/.claude/commands/lint.md +48 -0
- package/templates/javascript-typescript/.claude/commands/npm-scripts.md +48 -0
- package/templates/javascript-typescript/.claude/commands/refactor.md +55 -0
- package/templates/javascript-typescript/.claude/commands/test.md +61 -0
- package/templates/javascript-typescript/.claude/commands/typescript-migrate.md +51 -0
- package/templates/javascript-typescript/.claude/settings.json +142 -0
- package/templates/javascript-typescript/.mcp.json +80 -0
- package/templates/javascript-typescript/CLAUDE.md +185 -0
- package/templates/javascript-typescript/README.md +259 -0
- package/templates/javascript-typescript/examples/angular-app/.claude/commands/components.md +63 -0
- package/templates/javascript-typescript/examples/angular-app/.claude/commands/services.md +62 -0
- package/templates/javascript-typescript/examples/node-api/.claude/commands/api-endpoint.md +46 -0
- package/templates/javascript-typescript/examples/node-api/.claude/commands/database.md +56 -0
- package/templates/javascript-typescript/examples/node-api/.claude/commands/middleware.md +61 -0
- package/templates/javascript-typescript/examples/node-api/.claude/commands/route.md +57 -0
- package/templates/javascript-typescript/examples/node-api/CLAUDE.md +102 -0
- package/templates/javascript-typescript/examples/react-app/.claude/commands/component.md +29 -0
- package/templates/javascript-typescript/examples/react-app/.claude/commands/hooks.md +44 -0
- package/templates/javascript-typescript/examples/react-app/.claude/commands/state-management.md +45 -0
- package/templates/javascript-typescript/examples/react-app/CLAUDE.md +81 -0
- package/templates/javascript-typescript/examples/vue-app/.claude/commands/components.md +46 -0
- package/templates/javascript-typescript/examples/vue-app/.claude/commands/composables.md +51 -0
- package/templates/python/.claude/commands/lint.md +111 -0
- package/templates/python/.claude/commands/test.md +73 -0
- package/templates/python/.claude/settings.json +153 -0
- package/templates/python/.mcp.json +78 -0
- package/templates/python/CLAUDE.md +276 -0
- package/templates/python/examples/django-app/.claude/commands/admin.md +264 -0
- package/templates/python/examples/django-app/.claude/commands/django-model.md +124 -0
- package/templates/python/examples/django-app/.claude/commands/views.md +222 -0
- package/templates/python/examples/django-app/CLAUDE.md +313 -0
- package/templates/python/examples/fastapi-app/.claude/commands/api-endpoints.md +513 -0
- package/templates/python/examples/fastapi-app/.claude/commands/auth.md +775 -0
- package/templates/python/examples/fastapi-app/.claude/commands/database.md +657 -0
- package/templates/python/examples/fastapi-app/.claude/commands/deployment.md +160 -0
- package/templates/python/examples/fastapi-app/.claude/commands/testing.md +927 -0
- package/templates/python/examples/fastapi-app/CLAUDE.md +229 -0
- package/templates/python/examples/flask-app/.claude/commands/app-factory.md +384 -0
- package/templates/python/examples/flask-app/.claude/commands/blueprint.md +243 -0
- package/templates/python/examples/flask-app/.claude/commands/database.md +410 -0
- package/templates/python/examples/flask-app/.claude/commands/deployment.md +620 -0
- package/templates/python/examples/flask-app/.claude/commands/flask-route.md +217 -0
- package/templates/python/examples/flask-app/.claude/commands/testing.md +559 -0
- package/templates/python/examples/flask-app/CLAUDE.md +391 -0
- package/templates/rust/.mcp.json +78 -0
- package/templates/rust/README.md +26 -0
package/README.md
CHANGED
|
@@ -176,6 +176,7 @@ The CLI allows you to selectively enable automation hooks that enhance your deve
|
|
|
176
176
|
- `CLAUDE.md` - Main configuration file for Claude Code
|
|
177
177
|
- `.claude/settings.json` - Language-specific settings with selected automation hooks
|
|
178
178
|
- `.claude/commands/` - Custom commands for common tasks
|
|
179
|
+
- `.mcp.json` - Model Context Protocol server configurations
|
|
179
180
|
|
|
180
181
|
### Automation Hooks
|
|
181
182
|
Each language template includes selectable automation hooks for:
|
|
@@ -184,6 +185,19 @@ Each language template includes selectable automation hooks for:
|
|
|
184
185
|
- **Stop**: Final checks before session ends (e.g., linting changed files, bundle analysis)
|
|
185
186
|
- **Notification**: Logging and monitoring of Claude Code activities
|
|
186
187
|
|
|
188
|
+
### MCP Servers (Model Context Protocol)
|
|
189
|
+
Configure external tools and services to extend Claude's capabilities:
|
|
190
|
+
- **IDE Integration** - VS Code language diagnostics and Jupyter kernel execution
|
|
191
|
+
- **Web Search** - Real-time web search for up-to-date information and documentation
|
|
192
|
+
- **Filesystem Tools** - Advanced file operations, monitoring, and directory management
|
|
193
|
+
- **Database Tools** - Database connections, schema inspection, and query execution
|
|
194
|
+
|
|
195
|
+
MCP servers are configured in `.mcp.json` and enable Claude to:
|
|
196
|
+
- Execute code in VS Code or Jupyter environments
|
|
197
|
+
- Search the web for current information
|
|
198
|
+
- Perform advanced file system operations
|
|
199
|
+
- Connect to databases and run queries
|
|
200
|
+
|
|
187
201
|
### Language-Specific Commands
|
|
188
202
|
Each language template includes optimized commands for:
|
|
189
203
|
- Testing (Jest, pytest, Cargo test, Go test)
|
|
@@ -274,22 +288,45 @@ Target directory: /path/to/your/project
|
|
|
274
288
|
◉ Stop: Run ESLint on changed files before stopping
|
|
275
289
|
```
|
|
276
290
|
|
|
277
|
-
6. **
|
|
291
|
+
6. **MCP Server Selection** 🔧
|
|
278
292
|
```
|
|
279
|
-
|
|
293
|
+
🔧 Select MCP servers to include (use space to select):
|
|
294
|
+
◉ IDE Integration - VS Code language diagnostics and code execution
|
|
295
|
+
◉ Web Search - Search the web for up-to-date information
|
|
296
|
+
◯ Filesystem Tools - Advanced file operations and monitoring
|
|
297
|
+
◯ Database Tools - Database connection and query capabilities
|
|
298
|
+
```
|
|
299
|
+
- Choose Model Context Protocol servers to extend Claude's capabilities
|
|
300
|
+
- IDE Integration provides VS Code diagnostics and Jupyter kernel execution
|
|
301
|
+
- Web Search enables real-time web searches within Claude conversations
|
|
302
|
+
- Additional tools for filesystem operations and database management
|
|
303
|
+
|
|
304
|
+
7. **Final Confirmation** 🚀
|
|
280
305
|
```
|
|
281
|
-
|
|
306
|
+
🚀 Setup Claude Code for javascript-typescript with react (5 commands) (9 hooks) (4 MCP)? (Y/n)
|
|
307
|
+
```
|
|
308
|
+
- Review your choices including selected commands, hooks, and MCP servers
|
|
309
|
+
- Shows total count of each component being installed
|
|
282
310
|
- Type 'n' to cancel, 'y' or Enter to proceed
|
|
283
311
|
|
|
284
|
-
|
|
312
|
+
8. **Installation** 📁
|
|
285
313
|
```
|
|
286
314
|
📋 Existing CLAUDE.md backed up to CLAUDE.md.backup
|
|
287
315
|
✓ Copied javascript-typescript/CLAUDE.md → CLAUDE.md
|
|
288
|
-
✓ Copied javascript-typescript/.claude → .claude
|
|
289
|
-
✓ Copied
|
|
290
|
-
|
|
316
|
+
✓ Copied base configuration and commands javascript-typescript/.claude → .claude
|
|
317
|
+
✓ Copied javascript-typescript/.mcp.json → .mcp.json (with selected MCPs)
|
|
318
|
+
✓ Copied framework commands javascript-typescript/examples/react-app/.claude/commands → .claude/commands
|
|
291
319
|
🔧 Installed 9 automation hooks
|
|
320
|
+
🔧 Installed 4 MCP servers
|
|
292
321
|
✅ Claude Code configuration setup complete!
|
|
322
|
+
📚 Next steps:
|
|
323
|
+
1. Review the generated CLAUDE.md file
|
|
324
|
+
2. Customize the configuration for your project
|
|
325
|
+
3. Start using Claude Code with: claude
|
|
326
|
+
💡 Language-specific features for javascript-typescript have been configured
|
|
327
|
+
🎯 Framework-specific commands for react are available
|
|
328
|
+
🔧 9 automation hooks have been configured
|
|
329
|
+
🔧 4 MCP servers have been configured
|
|
293
330
|
```
|
|
294
331
|
|
|
295
332
|
## 🛡️ Safe Installation
|
|
@@ -312,34 +349,109 @@ Target directory: /path/to/your/project
|
|
|
312
349
|
|
|
313
350
|
## Development
|
|
314
351
|
|
|
315
|
-
### Setup
|
|
352
|
+
### Setup for Contributing
|
|
316
353
|
```bash
|
|
317
|
-
git clone https://github.com/
|
|
354
|
+
git clone https://github.com/davila7/claude-code-templates.git
|
|
318
355
|
cd claude-code-templates/cli-tool
|
|
319
356
|
npm install
|
|
320
357
|
```
|
|
321
358
|
|
|
322
|
-
###
|
|
359
|
+
### Local Development
|
|
323
360
|
```bash
|
|
324
|
-
#
|
|
325
|
-
npm
|
|
361
|
+
# Link the package for local testing
|
|
362
|
+
npm link
|
|
363
|
+
|
|
364
|
+
# Test locally (will use your local changes)
|
|
365
|
+
claude-code-templates
|
|
326
366
|
|
|
327
367
|
# Test with specific options
|
|
328
|
-
|
|
368
|
+
claude-code-templates --language python --framework django
|
|
369
|
+
|
|
370
|
+
# Run test suite
|
|
371
|
+
npm test
|
|
372
|
+
|
|
373
|
+
# Unlink when done
|
|
374
|
+
npm unlink -g claude-code-templates
|
|
329
375
|
```
|
|
330
376
|
|
|
331
|
-
###
|
|
377
|
+
### Testing Changes
|
|
332
378
|
```bash
|
|
333
|
-
|
|
379
|
+
# Run the comprehensive test suite
|
|
380
|
+
npm test
|
|
381
|
+
|
|
382
|
+
# Test specific scenarios manually
|
|
383
|
+
npm start -- --dry-run --language javascript-typescript --framework react
|
|
384
|
+
npm start -- --dry-run --language python --framework django
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
### Project Structure
|
|
388
|
+
```
|
|
389
|
+
cli-tool/
|
|
390
|
+
├── src/ # Source code
|
|
391
|
+
│ ├── command-scanner.js # Scans and loads commands
|
|
392
|
+
│ ├── file-operations.js # Handles file copying
|
|
393
|
+
│ ├── hook-scanner.js # Manages automation hooks
|
|
394
|
+
│ ├── index.js # Main entry point
|
|
395
|
+
│ ├── prompts.js # Interactive CLI prompts
|
|
396
|
+
│ ├── templates.js # Template configuration
|
|
397
|
+
│ └── utils.js # Utility functions
|
|
398
|
+
├── templates/ # Language and framework templates
|
|
399
|
+
│ ├── common/
|
|
400
|
+
│ ├── javascript-typescript/
|
|
401
|
+
│ ├── python/
|
|
402
|
+
│ ├── go/
|
|
403
|
+
│ └── rust/
|
|
404
|
+
└── bin/ # Executable scripts
|
|
334
405
|
```
|
|
335
406
|
|
|
336
407
|
## Contributing
|
|
337
408
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
409
|
+
We welcome contributions! Here's how to get started:
|
|
410
|
+
|
|
411
|
+
### 1. Fork & Clone
|
|
412
|
+
```bash
|
|
413
|
+
# Fork the repository on GitHub, then:
|
|
414
|
+
git clone https://github.com/your-username/claude-code-templates.git
|
|
415
|
+
cd claude-code-templates
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
### 2. Create a Feature Branch
|
|
419
|
+
```bash
|
|
420
|
+
git checkout -b feature/your-feature-name
|
|
421
|
+
# or
|
|
422
|
+
git checkout -b fix/issue-description
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
### 3. Make Your Changes
|
|
426
|
+
- Add new language templates in `templates/`
|
|
427
|
+
- Add new framework examples in `templates/language/examples/`
|
|
428
|
+
- Update commands, hooks, or core functionality
|
|
429
|
+
- Follow existing code patterns
|
|
430
|
+
|
|
431
|
+
### 4. Test Thoroughly
|
|
432
|
+
```bash
|
|
433
|
+
cd cli-tool
|
|
434
|
+
npm test # Run test suite
|
|
435
|
+
npm start -- --dry-run # Manual testing
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
### 5. Submit a Pull Request
|
|
439
|
+
- Commit with clear, descriptive messages
|
|
440
|
+
- Push to your fork
|
|
441
|
+
- Open a PR with description of changes
|
|
442
|
+
- Link any related issues
|
|
443
|
+
|
|
444
|
+
### Adding New Languages
|
|
445
|
+
1. Create `templates/your-language/` directory
|
|
446
|
+
2. Add `CLAUDE.md`, `.claude/settings.json`, and `.mcp.json`
|
|
447
|
+
3. Create commands in `.claude/commands/`
|
|
448
|
+
4. Add framework examples in `examples/`
|
|
449
|
+
5. Update `src/templates.js` configuration
|
|
450
|
+
|
|
451
|
+
### Adding New Frameworks
|
|
452
|
+
1. Create `templates/language/examples/framework-name/`
|
|
453
|
+
2. Add framework-specific commands and CLAUDE.md
|
|
454
|
+
3. Update the framework detection logic if needed
|
|
343
455
|
|
|
344
456
|
## License
|
|
345
457
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-code-templates",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "CLI tool to setup Claude Code configurations with framework-specific commands
|
|
3
|
+
"version": "1.3.4",
|
|
4
|
+
"description": "CLI tool to setup Claude Code configurations with framework-specific commands, automation hooks and MCP Servers for your projects",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"create-claude-config": "bin/create-claude-config.js",
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"files": [
|
|
70
70
|
"bin/",
|
|
71
71
|
"src/",
|
|
72
|
+
"templates/",
|
|
72
73
|
"README.md"
|
|
73
74
|
]
|
|
74
75
|
}
|
package/src/command-scanner.js
CHANGED
|
@@ -7,7 +7,7 @@ const path = require('path');
|
|
|
7
7
|
* @returns {Array} Array of available commands with metadata
|
|
8
8
|
*/
|
|
9
9
|
function getAvailableCommands(language) {
|
|
10
|
-
const templatesDir = path.join(__dirname, '
|
|
10
|
+
const templatesDir = path.join(__dirname, '../templates');
|
|
11
11
|
const languageDir = path.join(templatesDir, language);
|
|
12
12
|
|
|
13
13
|
// Check if language directory exists
|
package/src/file-operations.js
CHANGED
|
@@ -4,7 +4,7 @@ const chalk = require('chalk');
|
|
|
4
4
|
const { getHooksForLanguage, filterHooksBySelection, getMCPsForLanguage, filterMCPsBySelection } = require('./hook-scanner');
|
|
5
5
|
|
|
6
6
|
async function copyTemplateFiles(templateConfig, targetDir) {
|
|
7
|
-
const templateDir = path.join(__dirname, '
|
|
7
|
+
const templateDir = path.join(__dirname, '../templates');
|
|
8
8
|
|
|
9
9
|
// Check if CLAUDE.md already exists
|
|
10
10
|
const claudeFile = path.join(targetDir, 'CLAUDE.md');
|
package/src/hook-scanner.js
CHANGED
|
@@ -267,7 +267,7 @@ function getHookDescription(hook, matcher, type) {
|
|
|
267
267
|
* @returns {Array} Array of available hooks for the language
|
|
268
268
|
*/
|
|
269
269
|
function getHooksForLanguage(language) {
|
|
270
|
-
const templateDir = path.join(__dirname, '
|
|
270
|
+
const templateDir = path.join(__dirname, '../templates', language);
|
|
271
271
|
const settingsPath = path.join(templateDir, '.claude', 'settings.json');
|
|
272
272
|
|
|
273
273
|
return getHooksFromSettings(settingsPath);
|
|
@@ -399,7 +399,7 @@ function getDefaultMCPSelection(serverId) {
|
|
|
399
399
|
* @returns {Array} Array of available MCPs for the language
|
|
400
400
|
*/
|
|
401
401
|
function getMCPsForLanguage(language) {
|
|
402
|
-
const templateDir = path.join(__dirname, '
|
|
402
|
+
const templateDir = path.join(__dirname, '../templates', language);
|
|
403
403
|
const mcpPath = path.join(templateDir, '.mcp.json');
|
|
404
404
|
|
|
405
405
|
return getMCPsFromFile(mcpPath);
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# Git Workflow Helper
|
|
2
|
+
|
|
3
|
+
Manage Git workflows with best practices and common operations.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
This command helps you perform common Git operations following best practices for collaborative development.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
/git-workflow
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## What this command does
|
|
16
|
+
|
|
17
|
+
1. **Guides through Git operations** with proper workflow
|
|
18
|
+
2. **Suggests best practices** for commits and branches
|
|
19
|
+
3. **Helps with conflict resolution** and merging
|
|
20
|
+
4. **Provides templates** for commit messages
|
|
21
|
+
5. **Manages branching strategies** (Git Flow, GitHub Flow)
|
|
22
|
+
|
|
23
|
+
## Common Workflows
|
|
24
|
+
|
|
25
|
+
### Feature Development
|
|
26
|
+
```bash
|
|
27
|
+
# Create and switch to feature branch
|
|
28
|
+
git checkout -b feature/user-authentication
|
|
29
|
+
|
|
30
|
+
# Work on your feature
|
|
31
|
+
# ... make changes ...
|
|
32
|
+
|
|
33
|
+
# Stage and commit changes
|
|
34
|
+
git add .
|
|
35
|
+
git commit -m "feat: add user authentication system
|
|
36
|
+
|
|
37
|
+
- Implement login/logout functionality
|
|
38
|
+
- Add password validation
|
|
39
|
+
- Create user session management
|
|
40
|
+
- Add authentication middleware"
|
|
41
|
+
|
|
42
|
+
# Push feature branch
|
|
43
|
+
git push -u origin feature/user-authentication
|
|
44
|
+
|
|
45
|
+
# Create pull request (via GitHub/GitLab interface)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Hotfix Workflow
|
|
49
|
+
```bash
|
|
50
|
+
# Create hotfix branch from main
|
|
51
|
+
git checkout main
|
|
52
|
+
git checkout -b hotfix/security-patch
|
|
53
|
+
|
|
54
|
+
# Fix the issue
|
|
55
|
+
# ... make changes ...
|
|
56
|
+
|
|
57
|
+
# Commit the fix
|
|
58
|
+
git commit -m "fix: resolve security vulnerability in auth module
|
|
59
|
+
|
|
60
|
+
- Patch XSS vulnerability in login form
|
|
61
|
+
- Update input validation
|
|
62
|
+
- Add CSRF protection"
|
|
63
|
+
|
|
64
|
+
# Push and create urgent PR
|
|
65
|
+
git push -u origin hotfix/security-patch
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Sync with Remote
|
|
69
|
+
```bash
|
|
70
|
+
# Update main branch
|
|
71
|
+
git checkout main
|
|
72
|
+
git pull origin main
|
|
73
|
+
|
|
74
|
+
# Update feature branch with latest main
|
|
75
|
+
git checkout feature/your-feature
|
|
76
|
+
git rebase main
|
|
77
|
+
# OR
|
|
78
|
+
git merge main
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Commit Message Conventions
|
|
82
|
+
|
|
83
|
+
### Conventional Commits Format
|
|
84
|
+
```
|
|
85
|
+
<type>[optional scope]: <description>
|
|
86
|
+
|
|
87
|
+
[optional body]
|
|
88
|
+
|
|
89
|
+
[optional footer(s)]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Common Types
|
|
93
|
+
- **feat**: New feature
|
|
94
|
+
- **fix**: Bug fix
|
|
95
|
+
- **docs**: Documentation changes
|
|
96
|
+
- **style**: Code style changes (formatting, etc.)
|
|
97
|
+
- **refactor**: Code refactoring
|
|
98
|
+
- **test**: Adding or updating tests
|
|
99
|
+
- **chore**: Maintenance tasks
|
|
100
|
+
|
|
101
|
+
### Examples
|
|
102
|
+
```bash
|
|
103
|
+
# Feature
|
|
104
|
+
git commit -m "feat(auth): add OAuth2 integration"
|
|
105
|
+
|
|
106
|
+
# Bug fix
|
|
107
|
+
git commit -m "fix(api): handle null response in user endpoint"
|
|
108
|
+
|
|
109
|
+
# Documentation
|
|
110
|
+
git commit -m "docs: update API documentation for v2.0"
|
|
111
|
+
|
|
112
|
+
# Breaking change
|
|
113
|
+
git commit -m "feat!: change API response format
|
|
114
|
+
|
|
115
|
+
BREAKING CHANGE: API responses now use 'data' wrapper"
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Branch Management
|
|
119
|
+
|
|
120
|
+
### Git Flow Strategy
|
|
121
|
+
```bash
|
|
122
|
+
# Main branches
|
|
123
|
+
main # Production-ready code
|
|
124
|
+
develop # Integration branch
|
|
125
|
+
|
|
126
|
+
# Supporting branches
|
|
127
|
+
feature/* # New features
|
|
128
|
+
release/* # Release preparation
|
|
129
|
+
hotfix/* # Quick fixes to production
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### GitHub Flow (Simplified)
|
|
133
|
+
```bash
|
|
134
|
+
# Only main branch + feature branches
|
|
135
|
+
main # Production-ready code
|
|
136
|
+
feature/* # All new work
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Conflict Resolution
|
|
140
|
+
|
|
141
|
+
### When Conflicts Occur
|
|
142
|
+
```bash
|
|
143
|
+
# Start merge/rebase
|
|
144
|
+
git merge feature-branch
|
|
145
|
+
# OR
|
|
146
|
+
git rebase main
|
|
147
|
+
|
|
148
|
+
# If conflicts occur, Git will list conflicted files
|
|
149
|
+
# Edit each file to resolve conflicts
|
|
150
|
+
|
|
151
|
+
# Mark conflicts as resolved
|
|
152
|
+
git add conflicted-file.js
|
|
153
|
+
|
|
154
|
+
# Continue the merge/rebase
|
|
155
|
+
git merge --continue
|
|
156
|
+
# OR
|
|
157
|
+
git rebase --continue
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Conflict Markers
|
|
161
|
+
```javascript
|
|
162
|
+
<<<<<<< HEAD
|
|
163
|
+
// Your current branch code
|
|
164
|
+
const user = getCurrentUser();
|
|
165
|
+
=======
|
|
166
|
+
// Incoming branch code
|
|
167
|
+
const user = getAuthenticatedUser();
|
|
168
|
+
>>>>>>> feature-branch
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Useful Git Commands
|
|
172
|
+
|
|
173
|
+
### Status and Information
|
|
174
|
+
```bash
|
|
175
|
+
git status # Check working directory status
|
|
176
|
+
git log --oneline # View commit history
|
|
177
|
+
git branch -a # List all branches
|
|
178
|
+
git remote -v # List remote repositories
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Undoing Changes
|
|
182
|
+
```bash
|
|
183
|
+
git checkout -- file.js # Discard changes to file
|
|
184
|
+
git reset HEAD file.js # Unstage file
|
|
185
|
+
git reset --soft HEAD~1 # Undo last commit (keep changes)
|
|
186
|
+
git reset --hard HEAD~1 # Undo last commit (discard changes)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Stashing Work
|
|
190
|
+
```bash
|
|
191
|
+
git stash # Save current work
|
|
192
|
+
git stash pop # Apply and remove latest stash
|
|
193
|
+
git stash list # List all stashes
|
|
194
|
+
git stash apply stash@{1} # Apply specific stash
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Best Practices
|
|
198
|
+
|
|
199
|
+
1. **Commit Often** - Make small, focused commits
|
|
200
|
+
2. **Write Clear Messages** - Use conventional commit format
|
|
201
|
+
3. **Test Before Committing** - Ensure code works
|
|
202
|
+
4. **Pull Before Push** - Keep history clean
|
|
203
|
+
5. **Use Branches** - Don't work directly on main
|
|
204
|
+
6. **Review Code** - Use pull requests for collaboration
|
|
205
|
+
7. **Keep History Clean** - Rebase feature branches when appropriate
|
|
206
|
+
|
|
207
|
+
## Git Hooks (Optional)
|
|
208
|
+
|
|
209
|
+
### Pre-commit Hook
|
|
210
|
+
```bash
|
|
211
|
+
#!/bin/sh
|
|
212
|
+
# .git/hooks/pre-commit
|
|
213
|
+
|
|
214
|
+
# Run linter
|
|
215
|
+
npm run lint
|
|
216
|
+
if [ $? -ne 0 ]; then
|
|
217
|
+
echo "Linting failed. Please fix errors before committing."
|
|
218
|
+
exit 1
|
|
219
|
+
fi
|
|
220
|
+
|
|
221
|
+
# Run tests
|
|
222
|
+
npm test
|
|
223
|
+
if [ $? -ne 0 ]; then
|
|
224
|
+
echo "Tests failed. Please fix tests before committing."
|
|
225
|
+
exit 1
|
|
226
|
+
fi
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Commit Message Hook
|
|
230
|
+
```bash
|
|
231
|
+
#!/bin/sh
|
|
232
|
+
# .git/hooks/commit-msg
|
|
233
|
+
|
|
234
|
+
# Check commit message format
|
|
235
|
+
if ! grep -qE "^(feat|fix|docs|style|refactor|test|chore)(\(.+\))?: .{1,50}" "$1"; then
|
|
236
|
+
echo "Invalid commit message format. Use conventional commits."
|
|
237
|
+
exit 1
|
|
238
|
+
fi
|
|
239
|
+
```
|