Skip to content
Back to skills

Git Rebase Main

ASecurity

Safely rebase the current feature branch on top of the latest origin/main. Use when preparing a branch for PR, UAT, or release.

  • 666 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added February 8, 2026
toolsgobashgit

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add majiayu000/claude-skill-registry --skill git-rebase-main --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Git Rebase Main?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Git Rebase Main
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-git-rebase-main/badge)](https://www.skillsdirectory.com/skills/majiayu000-git-rebase-main)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: git-rebase-main
description: Safely rebase the current feature branch on top of the latest origin/main. Use when preparing a branch for PR, UAT, or release.
---

# Git Rebase Main

## Purpose
Ensure the current feature branch includes all the latest changes from `main` before proceeding with code review, UAT, or release. This prevents merge conflicts and ensures tests run against the latest codebase.

## Hard Rules
### Must
- Fetch from origin before rebasing.
- Handle rebase conflicts by stopping and reporting to the user.
- Verify the branch is not `main` before rebasing.

### Must Not
- Force-push without user confirmation.
- Rebase if there are uncommitted changes.

## Actions

### 1. Pre-flight Checks
```bash
# Ensure we're not on main
current_branch=$(git branch --show-current)
if [[ "$current_branch" == "main" ]]; then
  echo "ERROR: Cannot rebase main onto itself. Switch to a feature branch first."
  exit 1
fi

# Ensure working directory is clean
if [[ -n "$(git status --porcelain)" ]]; then
  echo "ERROR: Working directory has uncommitted changes. Commit or stash them first."
  exit 1
fi
```

### 2. Fetch and Rebase
```bash
git fetch origin
git rebase origin/main
```

### 3. Handle Conflicts
If the rebase fails due to conflicts:
1. Report the conflicting files to the user.
2. Do NOT attempt to auto-resolve.
3. Wait for user to resolve and run `git rebase --continue`.

### 4. Force Push (with confirmation)
After a successful rebase, the branch history has changed. Ask the user before force-pushing:
```bash
git push --force-with-lease origin HEAD
```

## Golden Example
```bash
$ git fetch origin && git rebase origin/main
First, rewinding head to replay your work on top of it...
Applying: feat: add new formatting option
$ git push --force-with-lease origin HEAD
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.