---
name: ecc-git-workflow
description: Git workflow patterns including branching strategies, commit conventions, merge vs rebase, conflict resolution, and collaborative development best practices.
---

# Git Workflow

Git workflow patterns for individual and team development.

## When to Activate
- Setting up branching strategy for a project
- Reviewing PR conventions
- Resolving merge conflicts
- Standardizing commit messages

## Branching Strategy

### Main Branches
- `main` — production-ready, protected
- `develop` — integration branch (optional for solo dev)

### Supporting Branches
- `feature/xxx` — new features
- `fix/xxx` — bug fixes
- `refactor/xxx` — refactoring
- `docs/xxx` — documentation
- `chore/xxx` — tooling, deps, CI

## Commit Conventions

### Conventional Commits
```
feat: add user authentication
fix: resolve crash on empty search
docs: update README API section
refactor: extract payment validation
chore: bump dependencies
```

### Commit Style
- Present tense imperative ("add" not "added")
- First line ≤ 72 chars
- Body wraps at 72 chars
- Reference issues: `fixes #123`

## Merge vs Rebase

### Merge (default)
```
git checkout main
git merge feature/xxx
```
Preserves history tree. Use for public branches.

### Rebase (for cleanup)
```
git checkout feature/xxx
git rebase main
```
Linear history. Use before PR to avoid merge commits.

### Interactive Rebase
```
git rebase -i HEAD~5
```
Squash, reorder, or fixup commits.

## Conflict Resolution
1. `git merge` → resolve in editor
2. `git add` resolved files
3. `git merge --continue`

## Useful Commands
```bash
# Amend last commit (not pushed)
git commit --amend

# Undo last commit (keep changes)
git reset --soft HEAD~1

# Stash
git stash push -m "WIP: in progress"
git stash pop

# Interactive add
git add -p
```
