git-switch-commit

Commits selected files to another git branch while preserving uncommitted work via stash.

Updated Nov 7, 2024
One-click install
npx skills add https://github.com/jeremysball/dotfiles --skill git-switch-commit-jeremysball
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-switch-commit
Source: https://github.com/jeremysball/dotfiles/tree/main/.pi/skills-archive/git-switch-commit
Command: npx skills add https://github.com/jeremysball/dotfiles --skill git-switch-commit-jeremysball

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? When working on a dirty feature branch, committing one or two urgent files to main normally risks losing or disturbing all other uncommitted changes. This Skill automates the stash-switch-commit-push-restore cycle so you can ship a quick fix without touching your work in progress. ## Core Features & Use Cases - Selective File Commit: Stash everything, switch to the target branch, extract only the chosen files from the stash, and commit just those. - Interactive Confirmation: Prompts for file selection, target branch, and an inferred conventional commit message before any irreversible action. - Safety Guardrails: Aborts on stash pop conflicts or rejected pushes, restores the original branch on failure, and never force-resolves conflicts. - Use Case: You are mid-refactor on a feature branch when a teammate asks you to fix a config file on main. Use this Skill to commit only that file to main, push it, and return to your branch with all other changes intact. ## Quick Start Ask the agent to commit a specific dirty file to main using the git-switch-commit workflow while keeping all other uncommitted changes untouched.

Frequently Asked Questions about git-switch-commit

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

FAQPage Schema
How do I commit specific files to another branch without losing uncommitted changes?

Stash all changes with git stash push -u, switch to the target branch, extract only the needed files using git checkout stash@{0} -- <files>, commit and push them, then switch back and run git stash pop to restore everything else.

How to extract only some files from a git stash?

Use git checkout stash@{0} -- <file1> <file2> instead of git stash pop. This copies specific files out of the stash into your working tree without applying or removing the entire stash.

What happens if git stash pop causes a conflict after switching back?

The workflow aborts immediately and notifies you with the conflicting file paths. Your changes remain safe in the stash, and you can resolve the conflict manually before running git stash pop again.

Can I commit to a branch other than main with this workflow?

Yes. The workflow always asks you to confirm the target branch before switching, defaulting to main but accepting any branch name. The script version also supports a --branch flag.

What if the push to the remote branch is rejected?

The workflow aborts on non-fast-forward push rejections and tells you to pull first. It attempts to return you to your original branch so your stashed changes stay recoverable via git stash list.