Git Stash, Worktree, and Clean Cheat Sheet

Temporary work preservation, multi-worktree workflows, cleanup commands, and conflict-resolution reuse.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Stash Workflows

Save, inspect, apply, branch from, and manage stashes.

Create a named stash

Save tracked changes with a message.

bashANYgitstashworkflow
bash
git stash push -m "WIP before review"

Messages make stash history much easier to understand in long-running repositories.

Stash unstaged changes only

Keep staged changes in the index and stash the rest.

bashANYgitstashindex
bash
git stash push --keep-index -m "stash unstaged only"

Useful when you want to test or commit only what is staged while setting aside unrelated work.

Stash only specific paths

Temporarily save changes from selected files.

bashANYgitstashpathspec
bash
git stash push -m "stash selected files" -- path/to/file another/file

Advanced stash usage for partial working tree preservation.

List stashes with diffstat

See stash entries and a compact summary of their changes.

bashANYgitstashinspect
bash
git stash list --stat

Helpful when you have many stashes and need a quick overview of their scope.

Show full patch for a stash

Inspect the actual diff stored in a stash entry.

bashANYgitstashpatchinspect
bash
git stash show -p stash@{0}

Useful before applying or branching from an older stash.

Create a branch from a stash

Check out a new branch and apply a stash there.

bashANYgitstashbranchrecovery
bash
git stash branch recovered-wip stash@{0}

Very useful when a stash no longer applies cleanly on the current branch but should become dedicated work.

Worktree Workflows

Maintain multiple working directories from one repository.

List worktrees

Show all linked working trees for the repository.

bashANYgitworktreeinspect
bash
git worktree list

The first command to run when managing multiple checkouts from the same repository.

Create a detached worktree at a commit

Check out a specific commit in a new working tree.

bashANYgitworktreedetached-head
bash
git worktree add --detach ../investigation <commit_sha>

Useful for quick historical investigation without disturbing active branches.

Create worktree and new branch together

Add a worktree and create a new branch from current HEAD.

bashANYgitworktreebranch
bash
git worktree add -b hotfix ../hotfix

A fast way to spin up a new isolated working directory for urgent work.

Lock a worktree

Prevent a worktree from being pruned or accidentally removed.

bashANYgitworktreelock
bash
git worktree lock ../feature --reason "USB drive worktree"

Useful when the worktree lives on a removable or temporarily unavailable path.

Prune stale worktree administrative entries

Clean up references to missing worktree directories.

bashANYgitworktreeprunemaintenance
bash
git worktree prune

Helpful after manually deleting worktree directories outside Git.

Remove a worktree

Delete a linked worktree entry and directory.

bashANYgitworktreeremovedanger
bash
git worktree remove --force ../feature

Use `--force` only when the worktree has local changes or other blockers and you intentionally want it removed.

Clean and Temporary File Management

Remove untracked files safely and recover from build clutter.

Preview untracked file deletion

Dry-run a cleanup of untracked files.

bashANYgitcleanpreview
bash
git clean -n

Always preview before cleaning. This is the safest habit for `git clean`.

Delete untracked files

Remove untracked files from the working tree.

bashANYgitcleanuntracked
bash
git clean -f

Deletes untracked files only, not directories or ignored files.

Delete untracked files and directories

Remove untracked files and directories.

bashANYgitcleandirectories
bash
git clean -fd

Common when resetting a repository after generated build artifacts and local temp directories.

Delete ignored files too

Remove ignored and untracked files and directories.

bashANYgitcleanignoreddanger
bash
git clean -fdx

Very destructive in projects with ignored local configs or build outputs. Use carefully.

Interactive clean

Review and select files to remove interactively.

bashANYgitcleaninteractive
bash
git clean -i

Safer than force-cleaning when you want more control over what gets removed.

Rerere and Repeated Conflict Resolution

Record and reuse conflict resolutions across merges and rebases.

Enable rerere

Record and reuse conflict resolutions automatically.

bashANYgitrerereconflictsmerge
bash
git config --global rerere.enabled true

Excellent for repeated rebases, repeated cherry-picks, or long-running branches that see the same conflict patterns.

Show rerere diff

Inspect what rerere has recorded for conflict resolutions.

bashANYgitrererediff
bash
git rerere diff

Useful when verifying that rerere recorded the intended resolution.

Clear rerere state

Remove recorded conflict-resolution data.

bashANYgitrerereclear
bash
git rerere clear

Helpful if rerere recorded an incorrect or unwanted resolution pattern.

Recommended next

No recommendations yet.