This is the first, in what I expect to be a long running series of Git tips for both new and experienced Git users. Some are commands I use, but not often enough to remember the syntax. Others are config changes I like to make to my environment.
The List
The full list of my Git tips is here.
What is a Stash?
For those unfamiliar with a stash in Git, it's a command to save (stash) your pending changes without committing them.
I use it when I'm working on a feature, but get interrupted. This is my workflow:
- Stash my pending changes.
- Switch to another branch to fix whatever it is.
- Switch back to the branch I started on.
- Un-stash (
pop
) my stash. - Continue working on interesting new feature.
It's similar to a shelveset in Team Foundation Version Control, except that it's stored locally in your Git repository and not synced up to the server.
The Command
To create a stash with a custom message, the command is simply:
git stash save "My custom message"
And to un-stash the changes later and delete the stash:
git stash pop
Or if you want to keep the stash:
git stash apply