Git master

From JeremyDev87/codingbuddy · View interactive version

Git master is an AI agent skill from the GitHub repository JeremyDev87/codingbuddy. Use when performing git operations - commits, rebasing, cherry-picking, history cleanup, or conflict resolution. Ensures atomic commits, clean history, and consistent commit message style.

How to use this skill

Skill file

Git Master

Overview

Messy git history obscures intent, makes debugging harder, and wastes reviewer time. Clean history tells the story of WHY changes were made, not just WHAT changed.

Core principle: Every commit should be a single, complete, logical change that can be understood, reverted, or cherry-picked independently.

Violating the letter of this process is violating the spirit of clean version control.

The Iron Law

ONE LOGICAL CHANGE PER COMMIT. NO EXCEPTIONS.

If a commit does two things, it should be two commits. If a commit is incomplete, it should not exist yet.

No exceptions:

When to Use

Use for ANY git operation beyond trivial:

Use this ESPECIALLY when:

Don't skip when:

When NOT to Use

The Six Phases

Phase 1: Style Detection

BEFORE making any commit, understand the repo's conventions:

  1. Analyze Recent History

```bash

git log --oneline -20

```

  1. Detect Commit Message Pattern

| Pattern | Example | Convention |

|---------|---------|------------|

| Conventional Commits | feat(auth): add OAuth2 flow | type(scope): description |

| Imperative mood | Add user validation | Verb-first, present tense |

| Ticket prefix | [PROJ-123] Fix login bug | [TICKET] description |

| Emoji prefix | :bug: Fix null pointer | Emoji + description |

| Freeform | Fixed the login thing | No consistent pattern |

  1. Match the Detected Style

Completion criteria:

Phase 2: Atomic Commits

Every commit must be atomic — one logical change, complete and self-contained.

  1. Stage Selectively

```bash

# Stage specific files, not everything

git add src/auth/login.ts src/auth/login.test.ts

# For partial file staging

git add -p src/utils/helpers.ts

```

Never use git add . or git add -A unless you have verified every change belongs together.

  1. Verify Staged Content

```bash

git diff --cached # Review what you're about to commit

git diff # Check what's NOT staged

```

  1. Write the Commit Message

Structure:

```

<type>(<scope>): <what changed> (max 72 chars)

<why this change was needed>

<any important context>

Refs: #issue-number (if applicable)

```

Good vs Bad:

| Bad | Good |

|-----|------|

| fix stuff | fix(auth): prevent session timeout on token refresh |

| WIP | feat(cart): add quantity validation for checkout |

| updates | refactor(api): extract retry logic into shared middleware |

| fix tests | test(auth): cover edge case for expired JWT tokens |

  1. Verify Atomicity

Completion criteria:

Phase 3: Rebase Workflows

Use rebase to maintain a clean, linear history.

  1. Standard Rebase (update branch)

```bash

git fetch origin

git rebase origin/main

```

  1. Interactive Rebase (clean up commits)

```bash

git rebase -i HEAD~N # N = number of commits to review

```

Action guide:

| Action | When to Use |

|--------|-------------|

| pick | Keep commit as-is |

| reword | Fix commit message only |

| squash | Merge into previous, combine messages |

| fixup | Merge into previous, discard message |

| drop | Remove commit entirely |

  1. Safe Rebase Checklist

> AI Agent Note: Interactive commands (rebase -i, add -p) require terminal interaction. AI agents without interactive input support should use non-interactive alternatives (e.g., git rebase --onto, git add <specific-files>) or prepare the rebase todo list programmatically.

  1. If Rebase Goes Wrong

```bash

git rebase --abort # Cancel in-progress rebase

git reflog # Find pre-rebase state

git reset --hard HEAD@{N} # Restore (DESTRUCTIVE — uncommitted changes lost)

```

Completion criteria:

Phase 4: Cherry-Pick

Safely move individual commits between branches.

  1. Before Cherry-Picking
  1. Execute Cherry-Pick

```bash

git cherry-pick <commit-hash>

# For multiple commits

git cherry-pick <hash1> <hash2> <hash3>

# For a range

git cherry-pick <older-hash>..<newer-hash>

```

  1. Handle Cherry-Pick Conflicts

```bash

# View conflicting files

git status

# Resolve conflicts, then

git add <resolved-files>

git cherry-pick --continue

# Or abort if too complex

git cherry-pick --abort

```

  1. Verify After Cherry-Pick

Completion criteria:

Phase 5: History Cleanup

Fix mistakes without breaking history for others.

  1. Amend Last Commit

```bash

# Add forgotten changes

git add <forgotten-file>

git commit --amend

# Fix message only

git commit --amend -m "corrected message"

```

Only amend unpushed commits. Amending pushed commits requires force-push.

  1. Fixup Older Commits

```bash

# Create a fixup commit

git commit --fixup=<target-hash>

# Auto-squash during rebase

git rebase -i --autosquash HEAD~N

```

  1. Recovery with Reflog

```bash

# View recent HEAD movements

git reflog

# Restore accidentally deleted commit

git cherry-pick <reflog-hash>

# Restore to a previous state (DESTRUCTIVE — all uncommitted changes are lost)

git reset --hard HEAD@{N}

```

  1. Safety Rules

Completion criteria:

Phase 6: Conflict Resolution

Resolve merge conflicts systematically, not by guessing.

  1. Understand the Conflict

```bash

# See which files conflict

git status

# See what both sides changed

git diff --merge

git log --merge --oneline

```

  1. Resolve Each File
  1. Resolution Strategies

| Situation | Strategy |

|-----------|----------|

| One side is clearly correct | Take that side |

| Both changes needed | Combine manually |

| Changes are incompatible | Consult the other author |

| Complex logic conflict | Write a new implementation that satisfies both |

  1. After Resolving

```bash

git add <resolved-files>

git commit # or git rebase --continue / git merge --continue

```

  1. Verify Resolution

Completion criteria:

Verification Checklist

Before completing any git operation:

Red Flags — STOP

| Thought | Reality |

|---------|---------|

| "I'll clean up the history later" | Later never comes. Clean it now. |

| "Just one big commit is fine" | Big commits are impossible to review, revert, or bisect. |

| "Nobody reads commit messages" | git blame and git bisect users do. Future-you does. |

| "Force push is fine, I'm the only one on this branch" | Verify first. CI, bots, and reviewers may have fetched. |

| "The merge conflict is obvious, just take mine" | Obvious conflicts hide subtle logic bugs. Read both sides. |

| "I'll squash on merge anyway" | Squash loses the story. Clean history beats squashed history. |

| "Rebase is scary, I'll just merge" | Merge commits obscure linear history. Learn rebase. |

| "This commit message is good enough" | Future readers have zero context. Be specific. |

ALL of these mean: STOP. Follow the relevant phase.

Related Skills

| Skill | Relationship |

|-------|-------------|

| refactoring | Refactoring produces commits — use git-master for commit hygiene |

| test-driven-development | TDD cycle maps to atomic commits: one test + impl per commit |

| pr-all-in-one | PR preparation requires clean history — git-master feeds into it |

| deployment-checklist | Deploy from clean branches with verified history |

Related Agents

| Agent | When to Involve |

|-------|----------------|

| Code Reviewer | When commit organization affects review quality |

| DevOps Engineer | When branch strategy impacts CI/CD pipeline |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.