Git Mastery - Complete Git Expertise
π¨ CRITICAL GUIDELINES
Windows File Path Requirements
MANDATORY: Always Use Backslashes on Windows for File Paths
When using Edit or Write tools on Windows, you MUST use backslashes (\) in file paths, NOT forward slashes (/).
Examples:
- β WRONG:
D:/repos/project/file.tsx
- β
CORRECT:
D:\repos\project\file.tsx
This applies to:
- Edit tool file_path parameter
- Write tool file_path parameter
- All file operations on Windows systems
Documentation Guidelines
NEVER create new documentation files unless explicitly requested by the user.
- Priority: Update existing README.md files rather than creating new documentation
- Repository cleanliness: Keep repository root clean - only README.md unless user requests otherwise
- Style: Documentation should be concise, direct, and professional - avoid AI-generated tone
- User preference: Only create additional .md files when user specifically asks for documentation
Comprehensive guide for ALL Git operations from basic to advanced, including dangerous operations with safety guardrails.
TL;DR QUICK REFERENCE
Safety First - Before ANY Destructive Operation:
git status
git log --oneline -10
git branch backup-$(date +%Y%m%d-%H%M%S)
git reflog
User Preference Check:
- ALWAYS ASK: "Would you like me to create commits automatically, or would you prefer to handle commits manually?"
- Respect user's choice throughout the session
Overview
This skill provides COMPLETE Git expertise for ANY Git operation, no matter how advanced, niche, or risky. It covers:
MUST use this skill for:
- β
ANY Git command or operation
- β
Repository initialization, cloning, configuration
- β
Branch management and strategies
- β
Commit workflows and best practices
- β
Merge strategies and conflict resolution
- β
Rebase operations (interactive and non-interactive)
- β
History rewriting (filter-repo, reset, revert)
- β
Recovery operations (reflog, fsck)
- β
Dangerous operations (force push, hard reset)
- β
Platform-specific workflows (GitHub, Azure DevOps, Bitbucket)
- β
Advanced features (submodules, worktrees, hooks)
- β
Performance optimization
- β
Cross-platform compatibility (Windows/Linux/macOS)
Core Principles
1. Safety Guardrails for Destructive Operations
CRITICAL: Before ANY destructive operation (reset --hard, force push, filter-repo, etc.):
- Always warn the user explicitly
- Explain the risks clearly
- Ask for confirmation
- Suggest creating a backup branch first
- Provide recovery instructions
echo "β οΈ WARNING: This operation is DESTRUCTIVE and will:"
echo " - Permanently delete uncommitted changes"
echo " - Rewrite Git history"
echo " - [specific risks for the operation]"
echo ""
echo "Safety recommendation: Creating backup branch first..."
git branch backup-before-reset-$(date +%Y%m%d-%H%M%S)
echo ""
echo "To recover if needed: git reset --hard backup-before-reset-XXXXXXXX"
echo ""
read -p "Are you SURE you want to proceed? (yes/NO): " confirm
if [[ "$confirm" != "yes" ]]; then
echo "Operation cancelled."
exit 1
fi
2. Commit Creation Policy
ALWAYS ASK at the start of ANY Git task:
"Would you like me to:
- Create commits automatically with appropriate messages
- Stage changes only (you handle commits manually)
- Just provide guidance (no automatic operations)"
Respect this choice throughout the session.
3. Platform Awareness
Git behavior and workflows differ across platforms and hosting providers:
Windows (Git Bash/PowerShell):
- Line ending handling (core.autocrlf)
- Path separators and case sensitivity
- Credential management (Windows Credential Manager)
Linux/macOS:
- Case-sensitive filesystems
- SSH key management
- Permission handling
Hosting Platforms:
- GitHub: Pull requests, GitHub Actions, GitHub CLI
- Azure DevOps: Pull requests, Azure Pipelines, policies
- Bitbucket: Pull requests, Bitbucket Pipelines, Jira integration
- GitLab: Merge requests, GitLab CI/CD
Basic Git Operations
Repository Initialization and Cloning
git init
git init --initial-branch=main
git clone <url>
git clone <url> <directory>
git clone --depth 1 <url>
git clone --branch <branch> <url>
git clone --recurse-submodules <url>
Configuration
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git config --global init.defaultBranch main
git config --global core.autocrlf true
git config --global core.autocrlf input
git config --global core.editor "code --wait"
git config --global core.editor "vim"
git config --global diff.tool vscode
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait $MERGED'
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
git config --global alias.visual '!gitk'
git config --list
git config --global --list
git config --local --list
git config user.name
Basic Workflow
git status
git status -s
git status -sb
git add <file>
git add .
git add -A
git add -p
git rm <file>
git rm --cached <file>
git rm -r <directory>
git mv <old> <new>
git commit -m "message"
git commit -am "message"
git commit --amend
git commit --amend --no-edit
git commit --allow-empty -m "message"
git log
git log --oneline
git log --graph --oneline --all --decorate
git log --stat
git log --patch
git log -p -2
git log --since="2 weeks ago"
git log --until="2025-01-01"
git log --author="Name"
git log --grep="pattern"
git log -- <file>
git log --follow <file>
git diff
git diff --staged
git diff HEAD
git diff <branch>
git diff <commit1> <commit2>
git diff <commit>
git diff <branch1>...<branch2>