Git Stash Notes

What is Git Stash?

Git stash is a command that temporarily saves your uncommitted changes so you can switch branches or pull updates without losing your work.

Common Git Stash Commands

1. Save Uncommitted Changes

 git stash

This saves your uncommitted changes and reverts your working directory to the last committed state.

2. View Stashed Changes

git stash list

Lists all stashed changes with their stash index.

3. Apply the Most Recent Stash

git stash pop

Applies the most recent stash and removes it from the stash list.

4. Apply a Specific Stash Without Removing It

git stash apply stash@{index}

Applies a specific stash but keeps it in the stash list.

5. Drop a Specific Stash

git stash drop stash@{index}

Removes a specific stash from the stash list.

6. Clear All Stashes

git stash clear

Deletes all stashed changes permanently.

Use Case Example

Stash Changes Before Switching Branches

git stash
git checkout other-branch
git stash pop

This allows you to switch branches without committing unfinished work.

Additional Notes




Written by A.M. Rinas