Thinky Face

Thinky Face is your prompt library, finally organized. Unlimited prompt storage, full version control, fork other users' prompts, public & private sharing, MCP server, teams, and much more. Learn more.

Create Free Account

No credit card required

Git Rebase Main Claude Code Skill

Donn Felker @donnfelker Updated 9 months ago Public

Description

Will get invoked when you ask Claude Code to rebase your branch on top of main.

Place into ~/.claude/skills/git-rebase-main/SKILL.md

Prompt Files

SKILL.md


name: git-rebase-main

description: Rebase current branch onto latest main/master, resolve conflicts, push safely. Use for “rebase over main”, “sync with main”, “fix rebase conflicts”, “update branch with latest”.

Git Rebase Main

Rebase current branch onto origin/main (or master) with conflict resolution.

Pre-Flight Checks

Run ALL before starting:

# Detect default branch (main vs master)
git remote show origin | grep 'HEAD branch' | cut -d' ' -f5

# Check current state
git status --porcelain
git branch --show-current

STOP if:

  • On main/master → git checkout <feature-branch> first
  • Detached HEAD → git checkout <branch-name>
  • Rebase already in progress → jump to “Resume/Abort Existing Rebase”
  • Uncommitted changes → stash or commit (see below)

Stash if needed:

git stash push -m "pre-rebase-$(date +%s)"

Execute Rebase

git fetch origin
git rebase origin/main  # or origin/master

If clean → skip to “Finalize”.

Resolve Conflicts

Loop until done:

# List conflicts
git diff --name-only --diff-filter=U

# For each file: edit, remove markers, then:
git add <file>

# Continue
git rebase --continue

Conflict markers:

<<<<<<< HEAD
(main's code)
=======
(your code)
>>>>>>> commit-msg

Keep both where needed. Ensure code compiles/runs before continuing.

Resume/Abort Existing Rebase

# Check state
git status

# Resume after fixing conflicts
git rebase --continue

# OR abandon completely (restores pre-rebase state)
git rebase --abort

Finalize

# Restore stash if used
git stash list
git stash pop  # if applicable

# Push (rebase rewrites history)
git push --force-with-lease

Error Recovery

Problem Fix
“Cannot rebase: uncommitted changes” git stash push -m "temp"
“No upstream configured” git push -u origin HEAD after rebase
Branch behind after abort git fetch origin && git reset --hard origin/<branch>
Wrong base used git rebase --abort, verify with git merge-base HEAD origin/main
Conflicts keep recurring Check for duplicate commits: git log --oneline origin/main..HEAD

Key Flags

  • --force-with-lease: Safe force push (fails if remote changed)
  • --abort: Full undo to pre-rebase state
  • --continue: Proceed after resolving conflicts
  • --skip: Drop current commit (use sparingly)

Comments

Write a comment...

Press Enter to post

No comments yet. Be the first to comment.