back-to-main

Switches a git repository to the main branch and syncs it with origin.

Updated Feb 11, 2026
One-click install
npx skills add https://github.com/mcmurrym/coding-agent-skills --skill back-to-main-mcmurrym
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: back-to-main
Source: https://github.com/mcmurrym/coding-agent-skills/tree/main/agent-skills/back-to-main
Command: npx skills add https://github.com/mcmurrym/coding-agent-skills --skill back-to-main-mcmurrym

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? After finishing work on a feature branch, developers often need to return to an up-to-date main branch without leaving stale remote-tracking refs or accidentally discarding local changes. This Skill runs a safe, deterministic git workflow to do exactly that. ## Core Features & Use Cases - Pruned Fetch and Fast-Forward Pull: Runs git fetch --prune, git checkout main, and git pull --ff-only to sync main with origin. - Missing Local Branch Recovery: Creates and tracks main from origin/main when no local main branch exists. - Safe Failure Handling: Stops and reports blocking files if the pull fails due to local changes, without stashing, resetting, or discarding anything. - Use Case: After merging a feature branch pull request, ask the agent to return the repository to a clean, up-to-date main before starting the next task. ## Quick Start Use the back-to-main skill to switch this repository back to main and pull the latest changes from origin.

Frequently Asked Questions about back-to-main

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I switch back to the main branch in git?▼

Run git fetch --prune, then git checkout main, then git pull --ff-only. This updates remote-tracking refs, switches to main, and fast-forwards it to match origin without creating merge commits.

How to checkout main when it does not exist locally?▼

Run git checkout -b main --track origin/main to create a local main branch that tracks the remote, then run git pull --ff-only to sync it. This happens when the local main branch was never created or was deleted.

What does git pull --ff-only do?▼

git pull --ff-only only updates your branch if it can be fast-forwarded to the remote state, meaning no divergent local commits exist. It fails instead of creating a merge commit, keeping history linear and predictable.

Why does git pull fail with local changes?▼

The pull fails when uncommitted local modifications conflict with incoming changes. This workflow stops and reports the blocking files rather than stashing, resetting, or discarding changes, so you can resolve them manually.

What does git fetch --prune remove?▼

git fetch --prune deletes local remote-tracking references for branches that no longer exist on the remote. It keeps your branch list clean after feature branches are merged and deleted on origin.