Skip to content
git-merging-feature-branches-to-main-skill logo

Merging Feature Branches to Main

git-merging-feature-branches-to-main-skill

Use when feature branch is complete and reviewed, ready to merge to main - squashes multiple commits into single clean commit in main using git merge --squash

SKILL.md

Full skill instructions

Merging Feature Branches to Main

Overview

Merge a completed and reviewed feature branch into main using git merge --squash to create a single clean commit in main's history.

Core principle: Main branch shows feature-level history (one commit per user story), not development-level history (many TDD commits).

Workflow context:

  1. Worktree implementation → feature branch (via finishing-a-development-branch)
  2. Human review on feature branch
  3. Feature branch → main (THIS SKILL - squash merge)

When to Use

Use this skill when:

  • Feature branch has all implementation work merged in (from worktrees)
  • Human has reviewed the feature branch
  • Ready to integrate feature branch into main
  • Want single clean commit in main (not 10+ granular commits)
  • Using TDD workflow that created many commits during implementation

Do NOT use when:

  • Still working in worktree (use finishing-a-development-branch first)
  • Feature hasn't been reviewed yet
  • Tests are failing on feature branch
  • Working directly on main branch
  • Want to preserve all individual commits in main history

Background

We use TDD which creates many commits during development (test, implementation, refactor cycles). These granular commits are valuable during development but should be squashed to one commit when merging to main.

Prerequisites Checklist

Before starting, verify:

# 1. Check current branch (should be on feature branch)
git branch --show-current

# 2. Verify working directory is clean
git status
# Should show "working tree clean"

# 3. Ensure all work is committed
git log --oneline -5
# Review recent commits to confirm work is saved

# 4. Verify main branch exists
git branch -a | grep main

If any check fails, STOP and resolve before proceeding.

Step-by-Step Workflow

Step 1: Switch to Main Branch

git checkout main

If you have a remote, update main:

git pull origin main

Step 2: Perform Squash Merge

git merge --squash <feature-branch-name>

This stages all changes from feature branch WITHOUT creating a commit yet.

Verify changes are staged:

git status
# Should show "Changes to be committed"

Step 3: Create Commit with create-git-commit Skill

REQUIRED SUB-SKILL: Use create-git-commit skill to craft the commit message.

Do NOT write commit message manually. The create-git-commit skill ensures proper format, scope, and message quality.

# The create-git-commit skill will guide you through:
# - Analyzing the staged changes
# - Following repository commit message conventions
# - Creating a well-formatted commit message

After create-git-commit skill creates the commit, verify:

git log --oneline -1
# Should show your new squashed commit

Step 4: Delete Feature Branch

After successful merge, clean up the feature branch:

# Force delete (required since squash doesn't create merge commit)
git branch -D <feature-branch-name>

Why -D: The -D flag force-deletes because --squash doesn't create a merge commit, so git doesn't recognize the branch as "merged" with -d.

Step 5: Push to Remote (if applicable)

git push origin main

Step 6: Verification

Confirm main branch has clean history:

# View recent commits
git log --oneline -5

# Verify one commit for the feature (not 10+)
# Verify commit message follows conventions

Run tests on main to ensure everything works:

npm test
# Or your test command

Error Handling

ProblemSolution
Uncommitted changes on feature branchCommit or stash changes before switching
Merge conflicts after squashResolve conflicts, git add files, then create commit
Feature branch not foundVerify branch name with git branch -a
Already on main branchCheckout feature branch first, or specify branch name differently
Branch deletion failsUse -D flag for force delete (squash merges don't mark as "merged")

Quick Reference

# Complete workflow
git checkout main
git pull origin main                      # If using remote
git merge --squash <feature-branch>
# Use create-git-commit skill here
git branch -D <feature-branch>
git push origin main                      # If using remote
git log --oneline -5                      # Verify

Common Mistakes

❌ Writing commit message manually

git commit -m "Add feature"  # WRONG

✅ Using create-git-commit skill

  • Ensures proper format and conventions
  • Analyzes all changes in the squash
  • Creates comprehensive feature-level message

❌ Using -d flag for deletion

git branch -d feature-x  # FAILS
# Error: not fully merged

✅ Using -D flag

git branch -D feature-x  # WORKS
# Squash merges require force delete

❌ Forgetting to delete branch

  • Leaves stale branches cluttering repository
  • Makes it unclear which branches are active

✅ Always delete after successful merge

  • Keeps repository clean
  • Makes active work visible

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View