Advanced Usage
Power user techniques and advanced Git operations with GitGuru.
Advanced Operations
Many of these operations can rewrite Git history or permanently delete data. Always use
--dry-run when available and make sure you understand what each command does before executing.Interactive Rebasing
Interactive rebase is powerful for cleaning up commit history:
Squash Multiple Commits
bash
# Squash last 5 commits into one
gg ask "squash last 5 commits into one"
# Interactive rebase for more control
gg ask "interactive rebase last 5 commits"
# Squash all commits on feature branch
gg ask "squash all commits since branching from main"Reorder Commits
bash
# Learn about reordering
gg explain "reordering commits with rebase"
# Interactively reorder
gg ask "interactive rebase to reorder last 3 commits"Edit an Old Commit
bash
# Edit a specific commit
gg ask "edit commit abc123"
# Change commit message of old commit
gg ask "change message of commit abc123"
# Split a commit into multiple
gg ask "how do I split commit abc123 into multiple commits"Cherry-Picking
Apply specific commits from one branch to another:
bash
# Cherry-pick a single commit
gg ask "cherry pick commit abc123"
# Cherry-pick multiple commits
gg ask "cherry pick commits abc123 def456 ghi789"
# Cherry-pick a range of commits
gg ask "cherry pick commits from abc123 to def456"
# Cherry-pick without committing
gg ask "cherry pick commit abc123 without committing"Git Bisect for Bug Hunting
Find the commit that introduced a bug:
bash
# Learn about bisect
gg explain bisect
# Start bisecting
gg ask "start bisect between v1.0.0 and HEAD"
# Mark current commit as good/bad
gg ask "mark this commit as bad"
gg ask "mark this commit as good"
# End bisect
gg ask "end bisect"Bisect Workflow
Git bisect uses binary search to find the problematic commit. You test each commit and mark it as good or bad until Git identifies the exact commit that introduced the issue.
Using Reflog for Recovery
Reflog is your safety net for recovering lost commits:
bash
# View reflog
gg ask "show reflog"
# Recover a deleted branch
gg ask "recover deleted branch feature/lost"
# Restore to a previous state
gg ask "restore HEAD to where it was 5 operations ago"
# Find and recover lost commits
gg ask "find commits that are no longer on any branch"Rewriting History
Danger Zone
Never rewrite history on shared branches. These operations should only be used on local branches that haven't been pushed, or on personal branches.
Change Commit Author
bash
# Change author of last commit
gg ask "change author of last commit to 'John Doe <john@example.com>'"
# Change author of multiple commits
gg ask "change author of last 5 commits"Remove File from History
bash
# Remove sensitive file from entire history
gg ask "remove secrets.txt from git history completely"
# Remove large file from history
gg ask "remove build/large-file.zip from all commits"Clean Up Commit History
bash
# Remove empty commits
gg ask "remove all empty commits"
# Rewrite all commits to have consistent author
gg ask "rewrite history to change author email from old@email.com to new@email.com"Working with Submodules
bash
# Learn about submodules
gg explain submodules
# Add a submodule
gg ask "add submodule https://github.com/example/lib at path vendor/lib"
# Update all submodules
gg ask "update all submodules to latest"
# Clone with submodules
gg ask "how do I clone a repo with all its submodules"Git Worktrees
Work on multiple branches simultaneously:
bash
# Learn about worktrees
gg explain worktrees
# Create a worktree for a different branch
gg ask "create worktree for branch feature/other at path ../feature-work"
# List all worktrees
gg ask "list all worktrees"
# Remove a worktree
gg ask "remove worktree at ../feature-work"Creating and Applying Patches
bash
# Create a patch from commits
gg ask "create patch from last 3 commits"
# Create patch for specific file
gg ask "create patch for changes in src/app.ts"
# Apply a patch
gg ask "apply patch from file changes.patch"
# Apply patch with 3-way merge
gg ask "apply patch with 3-way merge"Git Hooks
Automate actions at various Git events:
bash
# Learn about hooks
gg explain "git hooks"
# Common hook examples
gg ask "show example pre-commit hook for running tests"
gg ask "show example commit-msg hook for validating messages"Advanced Diff Operations
bash
# Diff between branches
gg ask "show diff between main and feature/new"
# Diff specific commit range
gg ask "show diff between commits abc123 and def456"
# Diff with specific algorithm
gg ask "show diff using patience algorithm"
# Word-level diff
gg ask "show word-by-word diff for file.txt"Advanced Log Queries
bash
# Commits by date range
gg ask "show commits from last week"
gg ask "show commits between 2024-01-01 and 2024-01-31"
# Commits affecting specific code
gg ask "find commits that changed the function loginUser"
# Commits with specific patterns
gg ask "find all merge commits"
gg ask "find commits that added TODO comments"
# Commits statistics
gg ask "show commit statistics by author for last month"Recovery Scenarios
Recover Deleted Branch
bash
# Find the commit hash from reflog
gg ask "show reflog for deleted branches"
# Recreate the branch
gg ask "create branch recovered-feature from commit abc123"Recover Lost Commits
bash
# After a bad reset or rebase
gg ask "show all recent HEAD positions in reflog"
# Reset to before the mistake
gg ask "reset to HEAD@{5}"Fix Detached HEAD
bash
# Understand the situation
gg explain "detached HEAD"
# Create a branch to save your work
gg ask "create branch from current detached HEAD"
# Or return to a branch
gg ask "switch back to main branch"Scripting with GitGuru
Use GitGuru in scripts with the -y flag:
bash
#!/bin/bash
# Automated daily sync script
# Skip confirmations with -y
gg fetch -y
gg pull -y
gg push -y
# Or use dry-run for safety
gg sync --dry-runOptimizing AI Usage
Choose the right model for different tasks:
bash
# For quick, simple queries - use faster model
gg config --set ai.model=gemini-1.5-flash
gg ask "show last commit"
# For complex analysis - use more capable model
gg config --set ai.model=gemini-1.5-pro
gg log -n 50 --ai # Complex history analysisAdvanced Troubleshooting
Understanding Commands
bash
# Before executing, understand what will happen
gg ask "explain what 'git reset --hard HEAD~3' does"
# Get the raw Git command
gg ask "what git command undoes the last rebase"Recover from Mistakes
bash
# Undo a bad merge
gg ask "undo the last merge"
# Undo a bad rebase
gg ask "abort current rebase"
gg ask "undo the last rebase"
# Recover from reset
gg ask "undo last reset"Next Steps
- gg ask Reference - Full command documentation
- Best Practices - Tips for safe Git usage
- Workflows - Complete workflow examples