Git Expert
Expert in Git version control with comprehensive knowledge of workflows, best practices, and advanced operations. Provides guidance for basic operations, complex workflows, debugging, and team collaboration.
Capabilities
- Basic Operations: Clone, add, commit, push, pull, status, log, and diff operations with advanced flags
- Branch Management: Creating, switching, merging, rebasing, and managing branch strategies
- History & Inspection: Advanced log queries, blame analysis, reflog recovery, and code searching
- Undoing & Restoration: Safe and unsafe undo operations, reset strategies, restore operations
- Advanced Operations: Cherry-picking, stashing, sparse-checkout, worktrees, tagging, and remote management
- Searching & Debugging: Git grep, log search, and bisect for finding bugs
- Collaboration: Pull request workflows, code review processes, conflict resolution strategies
- Workflow Guidance: Gitflow, GitHub Flow, trunk-based development patterns
- Best Practices: Commit message conventions, branch naming, PR etiquette
- Tool Integration: GitHub, GitLab, Bitbucket, and git hooks
Expertise Areas
Basic Operations
- clone:
--depth=1 (shallow), --bare (server-side)
- add:
-p (patch mode), --intent-to-add (track without content)
- commit:
--amend, --fixup (for autosquash)
- push:
--force-with-lease (safe force push)
- pull:
--rebase (linear history)
- status: Working tree status
- log:
--oneline --graph, --follow, -S (pickaxe), -G (regex), --grep
- diff:
--staged, --name-only
Branching
- branch:
-d (safe delete), -D (force delete)
- checkout: Switch branches
- switch:
-c (create and switch)
- checkout -: Previous branch
- merge:
--no-ff (preserve history)
- rebase:
-i (interactive), --onto, --autosquash
History & Inspection
- log:
--oneline --graph, --follow (track renames), -S (code search), -G (regex), --grep (message search)
- diff:
--staged, --name-only
- blame:
-L (line range)
- show: Inspect commits
- reflog: Reference history (emergency recovery)
- grep:
-n (line numbers), -C3 (context)
Undoing & Restoration
- reset:
--soft (keep staged), --mixed (keep unstaged), --hard (discard all)
- restore:
--staged (unstage changes)
- revert: Create undo commit
Advanced Operations
- cherry-pick:
-n (no-commit mode)
- stash:
pop (apply and remove)
- sparse-checkout:
init, set (partial repository)
- worktree:
add, list, remove (multiple working directories)
- clean:
-fd (untracked files), -fdx (include ignored)
- tag:
-a (annotated), -d (delete)
- remote:
add, remove, set-url
- fetch:
--all --prune
- for-each-ref: Programmable ref listing
- rev-parse:
--short (get commit SHA)
- range-diff: Compare commit ranges
- bundle:
create, verify (portable git archive)
- maintenance:
start (background optimization)
- gc:
--aggressive (garbage collection)
Searching & Debugging
- grep:
-n, -C3 (search repository content)
- log:
--grep, -S, -G (search commits and code)
- bisect:
start, good, bad, run, reset (find bug introduction)
Input Requirements
When requesting Git assistance, provide:
- Context: What you're trying to accomplish (feature development, bug fix, refactoring)
- Current State: Current branch, uncommitted changes, repository status
- Constraints: Team conventions, workflow requirements, deployment considerations
- Specifics: Branch names, commit messages, conflict details (if applicable)
Output Formats
Guidance includes:
- Commands: Exact Git commands with flags and explanations
- Workflows: Step-by-step process for complex operations
- Best Practices: Recommendations for commit messages, branching, collaboration
- Examples: Code patterns and real-world scenarios
- Troubleshooting: Solutions for common problems and edge cases
- Safety Notes: Warnings about destructive operations
How to Use
Example invocations:
- "Help me create a feature branch and make a PR"
- "How do I resolve these merge conflicts?"
- "I need to undo my last commit but keep the changes"
- "Show me how to cherry-pick commits from another branch"
- "How can I find when this bug was introduced?"
- "Help me clean up my commit history with interactive rebase"
- "What's the best way to sync my fork with upstream?"
- "I accidentally committed sensitive data, how do I remove it?"
Best Practices
Commit Messages
- Follow Conventional Commits format (
feat:, fix:, docs:, style:, refactor:, test:, chore:)
- Use imperative mood ("Add feature" not "Added feature")
- Keep subject line under 50 characters
- Add detailed body for complex changes
- Reference issue numbers
Branching
- Use descriptive branch names (
feature/user-auth, fix/login-bug)
- Keep branches short-lived
- Delete merged branches
- Regularly sync with main branch
Workflow
- Pull before you push
- Commit early and often locally
- Keep commits atomic and focused
- Review your changes before committing (
git diff --staged)
- Use
.gitignore properly
- NEVER commit secrets or credentials
- Use
--force-with-lease instead of --force
- Prefer
git switch and git restore (modern commands)
Collaboration
- Write clear PR descriptions
- Request reviews from appropriate team members
- Respond to review comments promptly
- Keep PRs focused and reasonably sized
- Resolve conflicts locally before pushing
Workflow Strategies
GitHub Flow
- Create feature branch from
main
- Commit changes
- Open pull request
- Review and discuss
- Merge to
main
- Deploy from
main
Gitflow
- main: Production-ready code
- develop: Integration branch
- feature/: New features
- release/: Release preparation
- hotfix/: Production fixes
Trunk-Based Development
- Work on short-lived feature branches or directly on
main
- Use feature flags for incomplete features
- Continuous integration and deployment
- Frequent small merges
Common Patterns
Basic Workflow
git switch -c feature/new-feature
# Make changes...
git add -p # Interactive staging
git commit -m "feat: add new feature"
git push --force-with-lease
Conventional Commits
feat: - New feature
fix: - Bug fix
docs: - Documentation
style: - Formatting
refactor: - Code restructuring
test: - Tests
chore: - Maintenance
Conflict Resolution
git status # See conflicts
# Edit files to resolve
git add resolved-file.js
git commit
Interactive Rebase
git rebase -i HEAD~3
# Commands: pick, reword, edit, squash, fixup, drop
git commit --fixup <commit>
git rebase -i --autosquash HEAD~3
Finding Bugs
git bisect start
git bisect bad # Current is broken
git bisect good v1.0 # Known good version
# Test and mark good/bad
git bisect reset # When done
Sparse Checkout (Clone Specific Folders)
# Method 1: Clone with sparse-checkout from start (recommended)
git clone --filter=blob:none --sparse <url> <directory>
cd <directory>
git sparse-checkout set path/to/folder1 path/to/folder2
# Method 2: Clone with no checkout, then set sparse paths
git clone --no-checkout <url> <directory>
cd <directory>
git sparse-checkout init --cone
git sparse-checkout set path/to/folder1 path/to/folder2
git checkout main
# Method 3: Convert existing clone to sparse-checkout
cd existing-repo
git sparse-checkout init --cone
git sparse-checkout set path/to/folder1 path/to/folder2
# Add more paths to sparse checkout
git sparse-checkout add path/to/folder3
# Remove paths from sparse checkout
git sparse-checkout set path/to/folder1 # Only folder1 now
# List current sparse paths
git sparse-checkout list
# Disable sparse checkout (get full repo)
git sparse-checkout disable
# Clone only docs folder from a large repo
git clone --filter=blob:none --sparse https://github.com/org/repo.git
cd repo
git sparse-checkout set docs
# Clone multiple specific folders
git clone --filter=blob:none --sparse https://github.com/org/repo.git
cd repo
git sparse-checkout set src/api src/models tests/api
Limitations
- Cannot automatically resolve complex merge conflicts (requires human judgment)
- Git commands are destructive if misused (
--hard, --force)
- Some operations rewrite history (dangerous on shared branches)
- Requires understanding of repository state and team conventions
- Recovery from certain operations requires reflog knowledge
- Large binary files can cause performance issues
- Some advanced operations require Git 2.23+ for modern syntax
Resources
- Pro Git Book (free online at git-scm.com)
- GitHub Docs (docs.github.com)
- Conventional Commits (conventionalcommits.org)
- Git Flight Rules (problem-solution guide)
- Oh Shit, Git!? (ohshitgit.com) - Emergency fixes
1---2name: git-expert3description: Expert guidance for Git version control operations including branching strategies, advanced commands, workflow best practices, conflict resolution, and collaboration patterns.4---56# Git Expert78Expert in Git version control with comprehensive knowledge of workflows, best practices, and advanced operations. Provides guidance for basic operations, complex workflows, debugging, and team collaboration.910## Capabilities1112- **Basic Operations**: Clone, add, commit, push, pull, status, log, and diff operations with advanced flags13- **Branch Management**: Creating, switching, merging, rebasing, and managing branch strategies14- **History & Inspection**: Advanced log queries, blame analysis, reflog recovery, and code searching15- **Undoing & Restoration**: Safe and unsafe undo operations, reset strategies, restore operations16- **Advanced Operations**: Cherry-picking, stashing, sparse-checkout, worktrees, tagging, and remote management17- **Searching & Debugging**: Git grep, log search, and bisect for finding bugs18- **Collaboration**: Pull request workflows, code review processes, conflict resolution strategies19- **Workflow Guidance**: Gitflow, GitHub Flow, trunk-based development patterns20- **Best Practices**: Commit message conventions, branch naming, PR etiquette21- **Tool Integration**: GitHub, GitLab, Bitbucket, and git hooks2223## Expertise Areas2425### Basic Operations26- **clone**: `--depth=1` (shallow), `--bare` (server-side)27- **add**: `-p` (patch mode), `--intent-to-add` (track without content)28- **commit**: `--amend`, `--fixup` (for autosquash)29- **push**: `--force-with-lease` (safe force push)30- **pull**: `--rebase` (linear history)31- **status**: Working tree status32- **log**: `--oneline --graph`, `--follow`, `-S` (pickaxe), `-G` (regex), `--grep`33- **diff**: `--staged`, `--name-only`3435### Branching36- **branch**: `-d` (safe delete), `-D` (force delete)37- **checkout**: Switch branches38- **switch**: `-c` (create and switch)39- **checkout -**: Previous branch40- **merge**: `--no-ff` (preserve history)41- **rebase**: `-i` (interactive), `--onto`, `--autosquash`4243### History & Inspection44- **log**: `--oneline --graph`, `--follow` (track renames), `-S` (code search), `-G` (regex), `--grep` (message search)45- **diff**: `--staged`, `--name-only`46- **blame**: `-L` (line range)47- **show**: Inspect commits48- **reflog**: Reference history (emergency recovery)49- **grep**: `-n` (line numbers), `-C3` (context)5051### Undoing & Restoration52- **reset**: `--soft` (keep staged), `--mixed` (keep unstaged), `--hard` (discard all)53- **restore**: `--staged` (unstage changes)54- **revert**: Create undo commit5556### Advanced Operations57- **cherry-pick**: `-n` (no-commit mode)58- **stash**: `pop` (apply and remove)59- **sparse-checkout**: `init`, `set` (partial repository)60- **worktree**: `add`, `list`, `remove` (multiple working directories)61- **clean**: `-fd` (untracked files), `-fdx` (include ignored)62- **tag**: `-a` (annotated), `-d` (delete)63- **remote**: `add`, `remove`, `set-url`64- **fetch**: `--all --prune`65- **for-each-ref**: Programmable ref listing66- **rev-parse**: `--short` (get commit SHA)67- **range-diff**: Compare commit ranges68- **bundle**: `create`, `verify` (portable git archive)69- **maintenance**: `start` (background optimization)70- **gc**: `--aggressive` (garbage collection)7172### Searching & Debugging73- **grep**: `-n`, `-C3` (search repository content)74- **log**: `--grep`, `-S`, `-G` (search commits and code)75- **bisect**: `start`, `good`, `bad`, `run`, `reset` (find bug introduction)7677## Input Requirements7879When requesting Git assistance, provide:8081- **Context**: What you're trying to accomplish (feature development, bug fix, refactoring)82- **Current State**: Current branch, uncommitted changes, repository status83- **Constraints**: Team conventions, workflow requirements, deployment considerations84- **Specifics**: Branch names, commit messages, conflict details (if applicable)8586## Output Formats8788Guidance includes:8990- **Commands**: Exact Git commands with flags and explanations91- **Workflows**: Step-by-step process for complex operations92- **Best Practices**: Recommendations for commit messages, branching, collaboration93- **Examples**: Code patterns and real-world scenarios94- **Troubleshooting**: Solutions for common problems and edge cases95- **Safety Notes**: Warnings about destructive operations9697## How to Use9899Example invocations:100101- "Help me create a feature branch and make a PR"102- "How do I resolve these merge conflicts?"103- "I need to undo my last commit but keep the changes"104- "Show me how to cherry-pick commits from another branch"105- "How can I find when this bug was introduced?"106- "Help me clean up my commit history with interactive rebase"107- "What's the best way to sync my fork with upstream?"108- "I accidentally committed sensitive data, how do I remove it?"109110## Best Practices111112### Commit Messages113- Follow Conventional Commits format (`feat:`, `fix:`, `docs:`, `style:`, `refactor:`, `test:`, `chore:`)114- Use imperative mood ("Add feature" not "Added feature")115- Keep subject line under 50 characters116- Add detailed body for complex changes117- Reference issue numbers118119### Branching120- Use descriptive branch names (`feature/user-auth`, `fix/login-bug`)121- Keep branches short-lived122- Delete merged branches123- Regularly sync with main branch124125### Workflow126- Pull before you push127- Commit early and often locally128- Keep commits atomic and focused129- Review your changes before committing (`git diff --staged`)130- Use `.gitignore` properly131- NEVER commit secrets or credentials132- Use `--force-with-lease` instead of `--force`133- Prefer `git switch` and `git restore` (modern commands)134135### Collaboration136- Write clear PR descriptions137- Request reviews from appropriate team members138- Respond to review comments promptly139- Keep PRs focused and reasonably sized140- Resolve conflicts locally before pushing141142## Workflow Strategies143144### GitHub Flow1451. Create feature branch from `main`1462. Commit changes1473. Open pull request1484. Review and discuss1495. Merge to `main`1506. Deploy from `main`151152### Gitflow153- **main**: Production-ready code154- **develop**: Integration branch155- **feature/**: New features156- **release/**: Release preparation157- **hotfix/**: Production fixes158159### Trunk-Based Development160- Work on short-lived feature branches or directly on `main`161- Use feature flags for incomplete features162- Continuous integration and deployment163- Frequent small merges164165## Common Patterns166167### Basic Workflow168```bash169git switch -c feature/new-feature170# Make changes...171git add -p # Interactive staging172git commit -m "feat: add new feature"173git push --force-with-lease174```175176### Conventional Commits177- `feat:` - New feature178- `fix:` - Bug fix179- `docs:` - Documentation180- `style:` - Formatting181- `refactor:` - Code restructuring182- `test:` - Tests183- `chore:` - Maintenance184185### Conflict Resolution186```bash187git status # See conflicts188# Edit files to resolve189git add resolved-file.js190git commit191```192193### Interactive Rebase194```bash195git rebase -i HEAD~3196# Commands: pick, reword, edit, squash, fixup, drop197git commit --fixup <commit>198git rebase -i --autosquash HEAD~3199```200201### Finding Bugs202```bash203git bisect start204git bisect bad # Current is broken205git bisect good v1.0 # Known good version206# Test and mark good/bad207git bisect reset # When done208```209210### Sparse Checkout (Clone Specific Folders)211```bash212# Method 1: Clone with sparse-checkout from start (recommended)213git clone --filter=blob:none --sparse <url> <directory>214cd <directory>215git sparse-checkout set path/to/folder1 path/to/folder2216217# Method 2: Clone with no checkout, then set sparse paths218git clone --no-checkout <url> <directory>219cd <directory>220git sparse-checkout init --cone221git sparse-checkout set path/to/folder1 path/to/folder2222git checkout main223224# Method 3: Convert existing clone to sparse-checkout225cd existing-repo226git sparse-checkout init --cone227git sparse-checkout set path/to/folder1 path/to/folder2228229# Add more paths to sparse checkout230git sparse-checkout add path/to/folder3231232# Remove paths from sparse checkout233git sparse-checkout set path/to/folder1 # Only folder1 now234235# List current sparse paths236git sparse-checkout list237238# Disable sparse checkout (get full repo)239git sparse-checkout disable240241# Clone only docs folder from a large repo242git clone --filter=blob:none --sparse https://github.com/org/repo.git243cd repo244git sparse-checkout set docs245246# Clone multiple specific folders247git clone --filter=blob:none --sparse https://github.com/org/repo.git248cd repo249git sparse-checkout set src/api src/models tests/api250```251252## Limitations253254- Cannot automatically resolve complex merge conflicts (requires human judgment)255- Git commands are destructive if misused (`--hard`, `--force`)256- Some operations rewrite history (dangerous on shared branches)257- Requires understanding of repository state and team conventions258- Recovery from certain operations requires reflog knowledge259- Large binary files can cause performance issues260- Some advanced operations require Git 2.23+ for modern syntax261262## Resources263264- Pro Git Book (free online at git-scm.com)265- GitHub Docs (docs.github.com)266- Conventional Commits (conventionalcommits.org)267- Git Flight Rules (problem-solution guide)268- Oh Shit, Git!? (ohshitgit.com) - Emergency fixes