Przejdลบ do treล›ci

๐Ÿงณ Git Stash

git stash temporarily stores uncommitted changes so you can switch branches or work on something else without committing unfinished work.


๐ŸŽ“ Who This Is For

  • Beginners learning practical Git workflows
  • Intermediate users managing multiple tasks
  • Advanced engineers needing structured reference
  • DevOps, sysadmins and developers working with complex branching models

๐Ÿงฉ What Stash Does

  • Saves tracked changes (modified files)
  • Optionally saves untracked files
  • Clears your working directory
  • Lets you restore changes later

Itโ€™s like a โ€œclipboardโ€ for your working directory.


๐Ÿ”ง Basic Usage

Save current changes

1
git stash

This stashes: - modified tracked files - staged files


๐Ÿ”ง Restore changes

1
git stash pop

This: - applies the stash - removes it from the stash list

If you want to keep the stash:

1
git stash apply

๐Ÿ”ง List stashes

1
git stash list

Example output:

1
2
stash@{0}: WIP on feature/login
stash@{1}: WIP on main

๐Ÿ”ง Stash with message

1
git stash push -m "Fixing login bug"

๐Ÿ”ง Stash untracked files

By default, untracked files are NOT included.

To include them:

1
git stash -u

To include ignored files too:

1
git stash -a

๐Ÿ”ง Show stash contents

1
2
git stash show
git stash show -p

๐Ÿ”ง Apply a specific stash

1
git stash apply stash@{2}

๐Ÿ”ง Drop a stash

1
git stash drop stash@{0}

๐Ÿ”ง Clear all stashes

1
git stash clear

๐Ÿง  When to Use Stash

  • You need to switch branches quickly
  • You must pull latest changes but have local modifications
  • Youโ€™re interrupted by a hotfix
  • You want to test something without committing
  • Youโ€™re in the middle of a rebase and need to save work

โš ๏ธ Common Pitfalls

  • Stash does not include untracked files unless -u is used
  • Stash can cause conflicts when popping
  • Stash is local only (not shared across machines)
  • Stash can be lost if you clear it accidentally

๐Ÿงฉ Best Practices

  • Use messages (-m) to avoid confusion
  • Avoid keeping many stashes โ€” they become unmanageable
  • Prefer apply over pop when unsure
  • Use stash before risky operations (rebase, reset)