Checking Local Work Before Switching Branches

Before changing a checkout, identify staged, unstaged, and untracked work and decide how each part should be retained.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Read the current state
  2. Choose a reversible path
  3. Inspect what belongs to each piece of work
  4. Verify restoration as a separate action

Read the current state

A file may contain a staged fix and separately edited diagnostics. Another artifact may be untracked. Short status identifies those states, and a diff records the actual contents.

Choose a reversible path

A coherent local commit can preserve work on an appropriate branch. A stash can temporarily retain selected changes. Shelving an experiment describes why checking which files were saved is part of that choice.[1]

Inspect what belongs to each piece of work

Before switching branches, a working tree may contain staged work, unstaged fixes and a new fixture. Review those three states. Pick a preservation method that keeps the relevant files and records where they can be found. See short status and shelving a local experiment.

Staged: deliberate fix
Unstaged: debugging note
Untracked: fixture required by experiment
Decide what must be recoverable later before switching

Verify restoration as a separate action

Changes may carry across a switch when paths allow it, making them easy to misattribute to another task. After moving, check the new branch and local status. When restoring saved work, compare the expected files and tests.

References

  1. Scott Chacon and Ben Straub, Pro Git ↩