git-advanced-operations
Skill2 starsChanged 10 months agoMITView on GitHub
Advanced Git operations for daily development workflows. Use this skill when performing interactive rebases, recovering lost commits, configuring hooks, managing worktrees, working with stashes, or setting up Git LFS. Covers reflog recovery, autosquash, hook automation, parallel development with worktrees, and large file storage.
- Deletes or force-pushes
- Commits and pushes
In this repository38 other files it gives its agents.
- Data Engineering Cloud InfrastructureSkill
- data-eng-data-qualitySkill
- data-eng-streaming-patternsSkill
- data-eng-testing-patternsSkill
- data-eng-warehouse-patternsSkill
- DevOps CI/CD PatternsSkill
- devops-docker-patternsSkill
- devops-monitoring-observabilitySkill
- devops-terraform-patternsSkill
- git-workflow-patternsSkill
- modern-python-patternsSkill
- python-api-developmentSkill
- python-async-patternsSkill
- python-data-pipelinesSkill
- python-data-wranglingSkill
- python-devops-automationSkill
- python-error-handlingSkill
- python-package-developmentSkill
- python-performanceSkill
- python-testingSkill
- customizing-vectors-rSkill
- designing-oop-rSkill
- developing-packages-rSkill
- metaprogramming-rlangSkill
- optimizing-rSkill
- writing-tidyverse-rSkill
- sql-advanced-featuresSkill
- sql-analytics-patternsSkill
- sql-data-modelingSkill
- SQL Integration PatternsSkill
- sql-query-fundamentalsSkill
- sql-query-optimizationSkill
- sql-transformationsSkill
- API DesignSkill
- webdev-html-css-patternsSkill
- webdev-javascript-fundamentalsSkill
- webdev-react-patternsSkill
- webdev-typescript-patternsSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
Reflog is your safety net: - Every HEAD movement is recorded for 90 days.
- Distinctive: line 18
Non-destructive by default: - Prefer operations that create new commits over those that destroy history
- Distinctive: line 19
Never rewrite shared history: - Only rebase or amend commits that have not been pushed to a shared branch
- Distinctive: line 20
Automate repetitive checks: - Use hooks to enforce standards before code leaves your machine
- Distinctive: line 115
All available hook types and their arguments
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Git Advanced Operations
Power-user Git workflows for rewriting history, recovery, automation, and large repo management.
Core Principles
- Understand the object model - Commits are immutable snapshots; branches are movable pointers; HEAD tracks your current position
- Reflog is your safety net - Every HEAD movement is recorded for 90 days; almost nothing in Git is truly lost
- Non-destructive by default - Prefer operations that create new commits over those that destroy history
- Never rewrite shared history - Only rebase or amend commits that have not been pushed to a shared branch
- Automate repetitive checks - Use hooks to enforce standards before code leaves your machine
Interactive Rebase
Rewrite, reorder, squash, and clean up commit history before sharing
# Rebase last 5 commits interactively
git rebase -i HEAD~5
# In the editor, change pick to the desired action:
# pick abc1234 Add user model
# squash abc1235 Fix typo in user model
# reword abc1236 Add auth middleware
# edit abc1237 Add login endpoint
# drop abc1238 WIP debugging
# Autosquash: auto-arrange fixup/squash commits
git commit --fixup=abc1234
git rebase -i --autosquash HEAD~5
# Rebase onto a different base branch
git rebase --onto main feature-base feature-branchSee interactive-rebase.md for:
- Squash vs fixup vs reword workflows
- Edit mode for splitting commits
- Autosquash with
--fixupand--squashcommits - Rebase onto for transplanting branches
- Handling rebase conflicts
Reflog and Recovery
Recover lost commits and undo destructive operations
# View recent HEAD movements
git reflog --date=relative
# Recover a commit after accidental reset
git reflog
# abc1234 HEAD@{2}: commit: important work
git checkout -b recovery-branch abc1234
# Undo a rebase by resetting to pre-rebase state
git reflog
# abc1234 HEAD@{5}: rebase (start): checkout main
git reset --hard HEAD@{5}
# Recover a deleted branch
git reflog | grep "checkout: moving from deleted-branch"
git checkout -b restored-branch abc1234See reflog-recovery.md for:
- Reflog navigation and time-based references
- Recovering commits after reset, rebase, or amend
- Restoring deleted branches and stashes
- Using
git fsckfor dangling objects
Git Hooks
Automate checks and enforce standards at key Git events
# Pre-commit hook: lint and format before committing
cat > .git/hooks/pre-commit << 'HOOK'
#!/bin/sh
# Run linter on staged files only
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.py$')
if [ -n "$STAGED_FILES" ]; then
ruff check $STAGED_FILES || exit 1
ruff format --check $STAGED_FILES || exit 1
fi
HOOK
chmod +x .git/hooks/pre-commit
# Commit-msg hook: enforce conventional commit format
cat > .git/hooks/commit-msg << 'HOOK'
#!/bin/sh
PATTERN='^(feat|fix|docs|style|refactor|test|chore)(\(.+\))?: .{1,72}$'
if ! head -1 "$1" | grep -qE "$PATTERN"; then
echo "ERROR: Commit message must follow Conventional Commits format"
echo "Example: feat(auth): add OAuth2 login flow"
exit 1
fi
HOOK
chmod +x .git/hooks/commit-msgSee git-hooks.md for:
- Pre-push hooks for test enforcement
- Husky and lint-staged setup for team projects
- Sharing hooks via a committed
.githooks/directory - All available hook types and their arguments
Worktrees
Work on multiple branches simultaneously without stashing or cloning
# Create a worktree for reviewing a PR
git worktree add ../review-pr-42 pr-42-feature
# Create a worktree with a new branch
git worktree add -b hotfix/login-bug ../hotfix main
# List active worktrees
git worktree list
# Remove a worktree when done
git worktree remove ../review-pr-42
# Prune stale worktree references
git worktree pruneSee worktree-patterns.md for:
- PR review workflow with worktrees
- Parallel development across features
- Worktree cleanup and maintenance
- Bare repo with worktree-only workflow
Stash Management
Save and restore work-in-progress without committing
# Stash with a descriptive message
git stash push -m "WIP: refactoring auth middleware"
# Stash only specific files
git stash push -m "partial save" -- src/auth.py src/config.py
# Stash including untracked files
git stash push --include-untracked -m "with new files"
# List stashes and inspect contents
git stash list
git stash show -p stash@{0}
# Apply without removing from stash stack
git stash apply stash@{1}
# Create a branch from a stash
git stash branch new-feature stash@{0}See stash-lfs-patterns.md for:
- Partial stash with
--patch - Recovering dropped stashes from reflog
- Stash-based workflow patterns
Git LFS
Track large binary files without bloating the repository
# Install and initialize LFS
git lfs install
# Track file patterns
git lfs track "*.psd" "*.zip" "datasets/*.parquet"
# Verify tracked patterns
cat .gitattributes
# Check LFS status
git lfs status
git lfs ls-files
# Migrate existing large files to LFS
git lfs migrate import --include="*.bin" --everythingSee stash-lfs-patterns.md for:
- LFS setup and migration workflow
- Handling LFS in CI/CD
- Storage and bandwidth considerations
Anti-Patterns
| Avoid | Use Instead |
git push --force on shared branches | git push --force-with-lease to prevent overwriting others' work |
| Rebasing commits already pushed to shared branches | Merge or revert to preserve shared history |
| Giant squash of entire feature branch | Squash related commits into logical units |
| Stashing without messages | git stash push -m "description" for identifiable stashes |
| Committing large binaries directly | Git LFS for files over 1 MB |
| Copy-pasting hook scripts between repos | Husky + lint-staged or a shared .githooks/ directory |
git checkout for everything | git switch for branches, git restore for files |
git reset --hard without checking reflog | Note the current HEAD hash first, then reset |
Performance
Optimizations for large repositories
# Partial clone: skip downloading all blobs upfront
git clone --filter=blob:none https://github.com/org/large-repo.git
# Sparse checkout: only materialize needed directories
git sparse-checkout init --cone
git sparse-checkout set src/my-module tests/my-module
# Shallow clone: limit history depth
git clone --depth=1 --single-branch https://github.com/org/repo.git
# Speed up status in large repos
git config core.fsmonitor true
git config core.untrackedCache true
# Maintenance: schedule background optimization
git maintenance start
# Commit graph: speed up log and merge-base operations
git commit-graph write --reachablesource: Git documentation, Pro Git book, Git LFS documentation
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

