Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Une commande directe contourne le prompt de vérification. Examinez la source avant de l'exécuter.
Advanced git workflows including rebase, worktrees, bisect, hooks, and monorepo patterns
author
workspace-hub
category
devtools
capabilities
["Interactive rebase and history rewriting","Git worktrees for parallel development","Bisect for bug hunting","Rerere for conflict resolution","Reflog for recovery","Hooks and custom commands","Submodules and monorepo patterns"]
Master advanced git workflows for efficient version control. This skill covers interactive rebase, worktrees, bisect, rerere, reflog, hooks, and patterns for monorepos and submodules.
# Install pre-commit
pip install pre-commit
# Or with homebrew
brew install pre-commit
Core Capabilities
1. Interactive Rebase
Basic Interactive Rebase:
# Rebase last 5 commits
git rebase -i HEAD~5
# Rebase onto main
git rebase -i main
# Rebase from specific commit
git rebase -i abc123^
Interactive Rebase Commands:
pick abc123 First commit # Use commit as-is
reword def456 Second commit # Edit commit message
edit ghi789 Third commit # Stop to amend
squash jkl012 Fourth commit # Combine with previous
fixup mno345 Fifth commit # Combine, discard message
drop pqr678 Sixth commit # Remove commit
Common Rebase Workflows:
# Squash all commits into one
git rebase -i main
# Change all but first 'pick' to 'squash'# Reorder commits
git rebase -i HEAD~3
# Rearrange the pick lines# Split a commit
git rebase -i HEAD~3
# Change 'pick' to 'edit' on target commit
git reset HEAD^
git add -p # Add pieces
git commit -m "First part"
git add .
git commit -m "Second part"
git rebase --continue# Edit commit message
git rebase -i HEAD~3
# Change 'pick' to 'reword'
# Start bisect
git bisect start
# Mark current version as bad
git bisect bad
# Mark known good commit
git bisect good v1.0.0
# Git checks out a commit - test it# If bad:
git bisect bad
# If good:
git bisect good
# Continue until found# Git will show: "abc123 is the first bad commit"# End bisect
git bisect reset
Automated Bisect:
# Create test scriptcat > test-bug.sh << 'EOF'#!/bin/bash# Return 0 if good, non-zero if bad
npm test -- --grep "specific test"
EOF
chmod +x test-bug.sh
# Run automated bisect
git bisect start
git bisect bad HEAD
git bisect good v1.0.0
git bisect run ./test-bug.sh
# Git will find the bad commit automatically
git bisect reset
Bisect with Skip:
# If commit can't be tested (won't build)
git bisect skip
# Skip range of commits
git bisect skip abc123..def456
# When you resolve a conflict, git records the resolution
git merge feature-branch
# Resolve conflicts...
git add .
git commit
# Next time same conflict occurs, git auto-applies resolution
git merge another-branch
# "Resolved 'file.txt' using previous resolution."# If auto-resolution is wrong, forget it
git rerere forget path/to/file
Rerere Management:
# View recorded resolutionsls .git/rr-cache/
# Clean old resolutions
git rerere gc
# Show diff of recorded resolution
git rerere diff
5. Git Reflog
Basic Reflog:
# Show reflog
git reflog
# Show reflog with dates
git reflog --date=relative
# Show reflog for specific ref
git reflog show feature-branch
# Output# abc123 HEAD@{0}: commit: Latest commit# def456 HEAD@{1}: checkout: moving from main to feature# ghi789 HEAD@{2}: commit: Previous commit
Recovery with Reflog:
# Recover deleted branch
git reflog
# Find last commit of deleted branch: abc123
git checkout -b recovered-branch abc123
# Undo hard reset
git reflog
# Find state before reset: HEAD@{2}
git reset --hard HEAD@{2}
# Recover lost stash
git fsck --unreachable | grep commit
git show <commit-hash>
git stash apply <commit-hash>
# Recover from bad rebase
git reflog
# Find pre-rebase state: HEAD@{5}
git reset --hard HEAD@{5}
#!/bin/bash# .git/hooks/pre-push# ABOUTME: Pre-push hook for safety checks# ABOUTME: Prevents pushing to protected branches
BRANCH=$(git rev-parse --abbrev-ref HEAD)
PROTECTED_BRANCHES="^(main|master|production)$"ifecho"$BRANCH" | grep -qE "$PROTECTED_BRANCHES"; thenecho"ERROR: Direct push to $BRANCH is not allowed."echo"Please create a pull request instead."exit 1
fi# Run full test suite before pushecho"Running tests before push..."
npm test || exit 1
echo"Pre-push checks passed!"
#!/bin/bash# scripts/submodule-sync.sh# ABOUTME: Synchronize all submodules# ABOUTME: Updates submodules to latest remote commitsset -e
echo"Synchronizing submodules..."# Initialize any new submodules
git submodule init
# Update all submodules to tracked branch
git submodule update --remote --merge
# Show status
git submodule status
echo"Submodules synchronized!"
9. Monorepo Patterns
Sparse Checkout:
# Enable sparse checkout
git sparse-checkout init
# Set patterns
git sparse-checkout set packages/app packages/shared
# Add more patterns
git sparse-checkout add docs
# Disable sparse checkout
git sparse-checkout disable
Working with Monorepos:
# Clone specific directory only
git clone --filter=blob:none --sparse https://github.com/user/monorepo
cd monorepo
git sparse-checkout set packages/my-package
# Shallow clone for faster checkout
git clone --depth 1 --filter=blob:none --sparse https://github.com/user/monorepo
# Partial clone (fetch objects on demand)
git clone --filter=blob:none https://github.com/user/monorepo
Monorepo Commit Strategy:
# Commit message with scope
git commit -m "feat(package-name): add feature X"# Using conventional commits
feat(api): add new endpoint
fix(web): resolve routing issue
chore(deps): update dependencies
docs(shared): improve API documentation
# .github/workflows/pr-check.ymlname:PRCheckson:pull_request:branches: [main]
jobs:validate:runs-on:ubuntu-lateststeps:-uses:actions/checkout@v4with:fetch-depth:0-name:Validatecommitmessagesrun:|
COMMITS=$(git log --format="%s" origin/main..HEAD)
PATTERN="^(feat|fix|docs|style|refactor|test|chore)(\(.+\))?: .+"
while IFS= read -r commit; do
if ! echo "$commit" | grep -qE "$PATTERN"; then
echo "Invalid commit message: $commit"
exit 1
fi
done <<< "$COMMITS"
-name:Checkformergecommitsrun:|
MERGE_COMMITS=$(git log --merges origin/main..HEAD --oneline)
if [ -n "$MERGE_COMMITS" ]; then
echo "Merge commits found. Please rebase instead."
echo "$MERGE_COMMITS"
exit 1
fi
-name:Runtestsrun:npmtest
3. Git Flow Helper Functions
# Add to ~/.bashrc# Start feature
gf-start() {
local feature="$1"
git checkout main
git pull
git checkout -b "feature/$feature"
}
# Finish feature
gf-finish() {
local branch=$(git rev-parse --abbrev-ref HEAD)
git checkout main
git pull
git merge --no-ff "$branch"
git branch -d "$branch"
}
# Start hotfix
gh-start() {
local hotfix="$1"
git checkout main
git pull
git checkout -b "hotfix/$hotfix"
}
# Sync branch with maingsync() {
local branch=$(git rev-parse --abbrev-ref HEAD)
git fetch origin main:main
git rebase main
}
Best Practices
1. Commit History
# Write good commit messages
git commit -m "feat(auth): add OAuth2 support
- Add Google OAuth provider
- Implement token refresh logic
- Add user profile sync
Closes #123"# Keep commits atomic# One logical change per commit# Use conventional commits# feat: new feature# fix: bug fix# docs: documentation# style: formatting# refactor: code restructure# test: add tests# chore: maintenance
2. Branch Strategy
# Feature branches from main
git checkout -b feature/add-auth main
# Hotfix branches from main
git checkout -b hotfix/fix-login main
# Keep branches short-lived# Merge frequently# Delete merged branches
git branch -d feature/add-auth
3. Rebase vs Merge
# Use rebase for:# - Cleaning up local commits# - Updating feature branch from main
git rebase main
# Use merge for:# - Integrating feature into main# - Preserving branch history
git merge --no-ff feature/add-auth
Troubleshooting
Common Issues
Accidental commit to wrong branch:
# Move commit to new branch
git branch new-branch
git reset --hard HEAD~1
git checkout new-branch
Undo merge:
# If not pushed
git reset --hard HEAD~1
# If pushed
git revert -m 1 <merge-commit>