GIT FIELD GUIDE // 02

Isolate work and move between Git branches safely

Create a focused feature branch, protect unfinished changes, and return without mixing unrelated work.

Scenario

Several features are moving at once and you must keep their histories under control.

BEFORE YOU START

Prerequisites and boundaries

  • Start from the repository and base branch that should own the new work.
  • Check whether the working tree already contains changes that belong elsewhere.
  • Know whether untracked files must be included when temporarily stashing work.

OPERATIONAL REASONING

Why this sequence matters

The goal is not merely to memorize commands. Each inspection, change, and verification step reduces a different failure mode.

01

Choose a clean branch point

The new branch inherits the currently checked-out commit, so the starting branch matters.

02

Commit or stash before switching

Unfinished changes can follow a checkout or block it; making their ownership explicit prevents accidental mixing.

03

Restore only after returning

A stash should be applied to the branch whose context and files it was created from.

STANDARD PROCEDURE

Develop a feature on an isolated branch and return to the integration branch safely.

A clean status check precedes branch creation; the feature is staged and committed before leaving its branch.

  1. 01
  2. 02
    git switch -c feature/loginGit switch documentation
  3. 03
  4. 04
    git commit -m "Add login feature"Git commit documentation
  5. 05

INCIDENT RESPONSE

Temporarily protect unfinished work, inspect another branch, then return and restore the original work.

The unfinished changes are identified and stashed before leaving the feature branch, then restored only after returning to that same branch.

  1. 01
  2. 02
    git stash push -m "feature wip"Git stash documentation
  3. 03
  4. 04
    git switch feature/loginGit switch documentation
  5. 05

COMMON FAILURE MODES

What usually goes wrong

  • The feature branch was created from a stale or unintended base branch.
  • git stash pop removed the stash entry before conflicts were fully understood.
  • A force-deleted branch contained commits that were not reachable anywhere else.

VERIFICATION

Evidence to collect

  • git branch --show-current reports the intended branch.
  • git status shows only changes that belong to the current task.
  • git log --oneline --decorate confirms the branch points at the expected commit.