
Thegit stash is probably one of my most used git commands afterpull
andpush
.
This command can be useful when you need to switch branches, but the current changes are not ready to be committed. Or you're experimenting with the code but unsure if it's worth committing to the history of the repository. The stashing allows you to temporarily set aside the current work which can also be good if you want to sync the local branch with the remote repository.
The simplest workflow withgit stash
is just to usegit stash
which will save your local modifications away and reverts the working directory to match the HEAD commit.
Then later on when you want to come back to your modification, usegit stash pop
.
However there are more power to this command than the example above. Here are some other sub-commands to thegit stash
command.
# List the stash entries that you currently have.git stash list# Creates and checks out a new branch named <branchname># with the stashed codegit stash branch <branchname># Stash with a messagegit stash push-m"<descriptive message>"# Stash untracked filesgit stash-u# Apply a specific, n, stash from the stash listgit stash apply stash@{n}
I like to use the commandgit stash push -m"my message"
when stashing, that will make it far easier to know what each stash is containing.
Will look like this when using thegit stash list
command.
Happy stashing!
Top comments(6)

- LocationUSA
- EducationRidgewater College
- Pronounsawe/some
- WorkLead Software Engineer @ProAg
- Joined
git stash --all
is generally what a dev wants. Stash everything that is or isn't tracked. I have my aliased togit sta

- LocationSweden
- EducationKTH Royal Institute of Technology
- WorkSoftware developer
- Joined
Indeed, that is a great flag to use and a great recommendation, thanks!

- LocationSofia, Bulgaria
- WorkDevEx @ Materialize | Community Manager @ DigitalOcean | Co-Founder @ DevDojo | Docker Captain
- Joined
Great post! 👏

- LocationIndia
- EducationSaffrony Institute of Technology
- Pronounshe/him
- WorkEngineering Student
- Joined
didn't knew about this, will use it from now, thank you !!

- LocationVilleurbanne, France
- EducationArts et Métiers
- WorkVP Technology
- Joined
git stash is a dear old friend, I'm happy to see some people loves it and are promoting its use
For further actions, you may consider blocking this person and/orreporting abuse