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
Create a named stash
git stash push -m "WIP before review"

# Save tracked changes with a message.

Stash unstaged changes only
git stash push --keep-index -m "stash unstaged only"

# Keep staged changes in the index and stash the rest.

Stash only specific paths
git stash push -m "stash selected files" -- path/to/file another/file

# Temporarily save changes from selected files.

List stashes with diffstat
git stash list --stat

# See stash entries and a compact summary of their changes.

Show full patch for a stash
git stash show -p stash@{0}

# Inspect the actual diff stored in a stash entry.

Create a branch from a stash
git stash branch recovered-wip stash@{0}

# Check out a new branch and apply a stash there.

## Worktree Workflows
List worktrees
git worktree list

# Show all linked working trees for the repository.

Create a detached worktree at a commit
git worktree add --detach ../investigation <commit_sha>

# Check out a specific commit in a new working tree.

Create worktree and new branch together
git worktree add -b hotfix ../hotfix

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

Lock a worktree
git worktree lock ../feature --reason "USB drive worktree"

# Prevent a worktree from being pruned or accidentally removed.

Prune stale worktree administrative entries
git worktree prune

# Clean up references to missing worktree directories.

Remove a worktree
git worktree remove --force ../feature

# Delete a linked worktree entry and directory.

## Clean and Temporary File Management
Preview untracked file deletion
git clean -n

# Dry-run a cleanup of untracked files.

Delete untracked files
git clean -f

# Remove untracked files from the working tree.

Delete untracked files and directories
git clean -fd

# Remove untracked files and directories.

Delete ignored files too
git clean -fdx

# Remove ignored and untracked files and directories.

Interactive clean
git clean -i

# Review and select files to remove interactively.

## Rerere and Repeated Conflict Resolution
Enable rerere
git config --global rerere.enabled true

# Record and reuse conflict resolutions automatically.

Show rerere diff
git rerere diff

# Inspect what rerere has recorded for conflict resolutions.

Clear rerere state
git rerere clear

# Remove recorded conflict-resolution data.

Recommended next

No recommendations yet.