git-knowledge

Explain Git working tree, index, and commit states to determine when stashing is required.

Updated Mar 31, 2026
One-click install
npx skills add https://github.com/shellicar/skills --skill git-knowledge
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-knowledge
Source: https://github.com/shellicar/skills/tree/main/skills/git-knowledge
Command: npx skills add https://github.com/shellicar/skills --skill git-knowledge

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Many developers misunderstand Git's three states—working tree, index, and commits—leading to unnecessary stash operations, pre‑emptive staging, and accidental data loss when switching branches or rebasing.

Core Features & Use Cases

  • Explains the three Git states and their roles.
  • Defines when stashing is truly required versus when it can be skipped.
  • Provides clear rules for unstaged, staged, and untracked files during branch switches, pulls, rebases, and merges.
  • Offers decision tables to help users decide the correct Git workflow in common scenarios such as creating a new branch, switching to an existing branch, or pulling remote changes.

Quick Start

Ask the git-knowledge skill to explain whether you need to stash before switching to branch 'feature-x'.

Frequently Asked Questions about git-knowledge

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

FAQPage Schema
Do I need to git stash before switching branches with uncommitted changes?

You only need to git stash before switching branches if your uncommitted changes conflict with files modified between the current and target branches. Git preserves non-conflicting working tree changes automatically during a branch switch.

What is the difference between the git working tree, index, and commits?

The git working tree holds your current modified files, the index is the staging area preparing changes for the next commit, and commits are the saved snapshots in version-control history. Understanding these three states prevents accidental data loss.

How do I know if git stash is required before a pull or rebase?

Git stash is required before a pull or rebase only when local working tree or index changes overlap with the incoming remote modifications. If no conflict detection triggers, Git safely proceeds without stashing.

When should I not use git stash for untracked files?

You should not use git stash for untracked files when switching branches, because untracked files do not conflict with branch operations and carry over automatically. Stashing them is unnecessary unless you explicitly want a clean working tree.

Can I switch branches with staged files without losing my index?

You can switch branches with staged files without losing your index if the staged changes do not conflict with the target branch. Git retains staged and unstaged modifications across branches when conflict detection finds no overlapping file changes.