Git stash

Let's say you are working in a branch and someone tell you to check another branch, or to make a fix in a different branch. You haven't finished your work, so you don't want to commit it yet. What do you do?

Git stash to the rescue

Git stash helps you to temporarily save your changes, so you can work in a different branch without losing it. Here is how you can use it.

Stashing your changes

git stash

This command saves your uncommitted changes, staged and unstaged, for later use.

Restoring you stashed changes

You can restore your changes by running:

git stash pop

This command removes the stash from the list, and apply it to your working branch. you can also use:

git stash apply

This command applies the stashed changes to your current branch, but it still keeps a copy in the stash list. It is useful if you want to apply the changes to different branches.

But, there is one small issue with git stash. By default Git won't stash untracked or ignored files.

To be able to stash them, you need to add -u option, like this:

git apply -u

For more information, check here.

Luis Güette
Luis Güette

I'm a tech guy and I love to make software products with the last technology trends.

© 2022 TAE Control Solution. All rights reserved.