agentleFS
justanestajustanesta/claude-code-resources/skills/git/git-advanced-operations/SKILL.md

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

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
  1. Distinctive:

    Reflog is your safety net: - Every HEAD movement is recorded for 90 days.

    line 17
  2. Distinctive:

    Non-destructive by default: - Prefer operations that create new commits over those that destroy history

    line 18
  3. Distinctive:

    Never rewrite shared history: - Only rebase or amend commits that have not been pushed to a shared branch

    line 19
  4. Distinctive:

    Automate repetitive checks: - Use hooks to enforce standards before code leaves your machine

    line 20
  5. Distinctive:

    All available hook types and their arguments

    line 115

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Git Advanced Operations

Power-user Git workflows for rewriting history, recovery, automation, and large repo management.

Core Principles

  1. Understand the object model - Commits are immutable snapshots; branches are movable pointers; HEAD tracks your current position
  2. Reflog is your safety net - Every HEAD movement is recorded for 90 days; almost nothing in Git is truly lost
  3. Non-destructive by default - Prefer operations that create new commits over those that destroy history
  4. Never rewrite shared history - Only rebase or amend commits that have not been pushed to a shared branch
  5. 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-branch

See interactive-rebase.md for:

  • Squash vs fixup vs reword workflows
  • Edit mode for splitting commits
  • Autosquash with --fixup and --squash commits
  • 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 abc1234

See reflog-recovery.md for:

  • Reflog navigation and time-based references
  • Recovering commits after reset, rebase, or amend
  • Restoring deleted branches and stashes
  • Using git fsck for 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-msg

See 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 prune

See 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" --everything

See stash-lfs-patterns.md for:

  • LFS setup and migration workflow
  • Handling LFS in CI/CD
  • Storage and bandwidth considerations

Anti-Patterns

AvoidUse Instead
git push --force on shared branchesgit push --force-with-lease to prevent overwriting others' work
Rebasing commits already pushed to shared branchesMerge or revert to preserve shared history
Giant squash of entire feature branchSquash related commits into logical units
Stashing without messagesgit stash push -m "description" for identifiable stashes
Committing large binaries directlyGit LFS for files over 1 MB
Copy-pasting hook scripts between reposHusky + lint-staged or a shared .githooks/ directory
git checkout for everythinggit switch for branches, git restore for files
git reset --hard without checking reflogNote 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 --reachable

source: Git documentation, Pro Git book, Git LFS documentation

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.