Git Stash Tutorial |Video upload date:  · Duration: PT14M36S  · Language: EN

Learn git stash commands and workflows to save uncommitted changes and switch branches safely

If you ever needed to switch branches mid chaos and did not want to commit half baked code to history you need git stash in your life. This guide gives you the commands and the attitude to stash work safely then bring it back when you are ready. It is everything about git stash for real developer workflows without the handholding or the judgment.

What git stash does and why you care

Think of git stash as a temporary pocket for your uncommitted changes. It removes changes from the working tree and stores them on a stack so you can switch branches or experiment without leaving a mess. It works with tracked files by default and can include untracked files when you ask nicely.

Save changes to stash

Use the push command to put work into the stash stack. Add a message so future you can stop guessing what this disaster was about.

git stash push -m "message"
# include untracked files
git stash push -m "message" --include-untracked
# or the short flag
git stash push -m "message" -u

These commands clear your working tree and save those edits on the stash stack. Switching branches then becomes less dramatic and more professional.

See what you have saved

List the stash stack to inspect entries. Each stash shows up as stash@{index} with whatever message you gave it.

git stash list

Pro tip keep meaningful messages unless you enjoy playing treasure hunt with your past self.

Reapply and remove stashes

When you want the changes back you have two main verbs. Apply will reapply and keep the stash. Pop will reapply and remove the top stash in one move.

# reapply and keep
git stash apply stash@{0}
# reapply and remove
git stash pop stash@{0}

Sometimes reapplying causes conflicts. Resolve them like a grown developer and then continue. The stash system will not hold your hand but it will keep your work safe.

Create a branch from a stash

When the stashed work needs its own life use the stash branch command. This creates a new branch that starts with the stashed changes so you can continue development without grafting patches by hand.

git stash branch my-feature stash@{0}

This is cleaner than copying files around or making a commit that will embarrass you later.

Drop or clear stashes

When a stash has outlived its usefulness you can remove it from the list. Drop removes one entry. Clear nukes everything if you are feeling decisive.

# remove a single stash
git stash drop stash@{0}
# remove all stashes
git stash clear

Use these commands with care. There is no trash can for stashes once you nuke them.

Quick workflow tips and developer tips

  • Use git stash push -m "meaningful message" so the history of your brain is readable.
  • Prefer git stash branch when the changes belong on their own feature line.
  • If you stash untracked files remember to include --include-untracked or -u
  • Resolve conflicts after apply or pop just like any merge conflict and then commit when ready.
  • Keep the stash list tidy so you do not confuse yourself on Monday morning.

Recap

git stash is the practical tool for saving uncommitted changes as you switch context. Use git stash push to save work and include untracked files when needed. Use git stash list to inspect entries and git stash apply or git stash pop to bring changes back. Create isolated work with git stash branch and clean up with git stash drop or git stash clear. Follow these developer tips and your version control workflow will be less chaotic and slightly more civilized.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.