agentleFS
poorvith-mppoorvith-mp/skills-developer/skills/git-operations/SKILL.md

git-operations

Skill0 starsChanged 3 months agoMITView on GitHub

Do the actual git work: branch, stage, commit, rebase, resolve conflicts, and recover with reflog and reset. Use when resolving merge conflicts, complex rebases, or git history repairs.

  • Reads credentials
  • Deletes or force-pushes
  • Commits and pushes

5 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Distinctive:

    Use interactive staging (git add -p) to review and stage distinct chunks rather than running blind git add ..

    line 22
  2. Distinctive:

    Never merge a branch with 14 "fix typo" or "WIP" commits into main.

    line 30
  3. Very specific:

    Never rebase a public shared branch (e.g.

    line 41
  4. Distinctive:

    Verify code compiles and passes unit tests before staging:

    line 51
  5. Distinctive:

    Result: All 4 commits restored to a proper named branch with zero code loss in 60 seconds.

    line 103

“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “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-operations

Core Philosophy

Git is not a magical black box where you type random commands found on StackOverflow hoping your branch fixes itself. Git is a content-addressable, immutable directed acyclic graph (DAG) of snapshot objects. Mastering Git operations means understanding object pointers, commits, trees, and the reflog—enabling you to resolve any merge conflict cleanly, rewrite messy commit history safely, and recover from accidental deletions with zero panic.


4-Step Professional Git Operations Discipline

Step 1: Atomic Branching & Clean Commit Craft

  1. The Principle of Atomic Commits:
    • Each commit represents exactly one logical change that compiles cleanly and passes tests.
    • Use interactive staging (git add -p) to review and stage distinct chunks rather than running blind git add ..
  2. Conventional Commit Standard:
    • Format: <type>(<scope>): <short imperative summary>
    • Types: feat, fix, refactor, perf, test, docs, chore.
    • Rule: Imperative present tense ("add user validation", not "added" or "adds").

Step 2: Interactive Rebasing & History Rewriting

  1. Squashing & Cleaning Feature Branches:
    • Never merge a branch with 14 "fix typo" or "WIP" commits into main.
    • Rebase interactively onto upstream main:
      git fetch origin main
      git rebase -i origin/main
    • Rebase Commands:
      • pick: Use commit as-is.
      • reword: Change commit message.
      • squash / fixup: Meld commit into previous commit (fixup discards commit message).
  2. The Golden Rule of Rebasing:
    • Never rebase a public shared branch (e.g. main or production). Only rebase local feature branches.

Step 3: Complex 3-Way Merge Conflict Resolution

  1. Enabling Modern Conflict Markers:
    • Configure Git to show the common ancestor base in conflict diffs:
      git config --global merge.conflictstyle zdiff3
  2. Systematic Conflict Resolution Protocol:
    • Identify the 3 states: <<<<<<< HEAD (your changes), ||||||| base (original state before both branched), >>>>>>> incoming (their changes).
    • Verify code compiles and passes unit tests before staging:
      git add <resolved-file>
      git rebase --continue
    • Abort cleanly if lost: git rebase --abort or git merge --abort.

Step 4: Emergency Recovery with Git Reflog & Reset

  1. Recovering Lost Commits:
    • Git almost never deletes committed objects immediately. The reference log (reflog) records every movement of HEAD.
    • View history of HEAD movements:
      git reflog
    • Restore branch state to prior snapshot:
      git reset --hard HEAD@{2}
  2. Safely Undoing Mistakes:
    • Undo last commit but keep changes staged: git reset --soft HEAD~1.
    • Undo last commit and unstage changes: git reset HEAD~1.

Deliverable Format: Git Runbook & Conflict Log (GIT-RUNBOOK.md)

# Git Incident Recovery & Rebase Runbook

## 1. Branch Health & Clean History Strategy
- **Target Branch**: `feature/auth-refactor` -> `main`
- **Rebase Base**: `origin/main` (latest commit `e4f1a09`)
- **Action Plan**: Interactive rebase squashing 8 WIP commits into 2 atomic commits.

## 2. Conflict Resolution Walkthrough
| File | Conflict Nature | Resolution Chosen | Verification |
|---|---|---|---|
| `src/auth.ts` | Overlapping imports | Combined both imports | `npm run build` passed |
| `prisma/schema.prisma` | Conflicting model fields | Kept both fields; reordered | `npx prisma validate` |

## 3. Disaster Recovery Plan (Reflog Snapshot)
- Pre-rebase HEAD: `HEAD@{1}: commit 7b2a9c1 "feat(auth): initial oauth scaffolding"`
- Emergency recovery command: `git reset --hard 7b2a9c1`

Worked Example: Rescuing a Detached HEAD State

  • Problem: Engineer accidentally checked out a commit hash directly, made 4 commits, and could not find them after switching back to main.
  • Diagnosis: Ran git reflog, identified the lost commit hash a81f3d2.
  • Remediation: Executed git branch feature/recovered-work a81f3d2.
  • Result: All 4 commits restored to a proper named branch with zero code loss in 60 seconds.

Verification Checklist

  • Feature branch rebased cleanly on latest origin/main prior to PR review.
  • Commits are squashed into atomic, logically distinct units with conventional commit messages.
  • merge.conflictstyle zdiff3 configured to inspect common ancestor during conflicts.
  • All unit and integration tests pass cleanly after conflict resolution.
  • Pre-rebase state noted from reflog before executing destructive operations.

Anti-Patterns

  • Force-Pushing Shared Branches: Running git push --force on main, destroying teammates' commits. (Always use --force-with-lease).
  • Committing Secrets: Adding .env files or API credentials into git tracking.
  • Giant Merge Dumps: Merging a 40-commit branch full of "wip", "fixed bug", "test" messages directly to main.

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.