Explaining Git Stash
The concern is documenting the point and usage of git stash
2 min readSep 15, 2022
NOUN
stash (plural stashes)
- A collection, sometimes hidden; a reserve.
They had quite a stash of food saved up for emergencies.
- (US, slang, informal, African-American Vernacular) A place where drugs are stored.
The dealers managed to store the dope in the stash just in time to avoid being caught by the police.
VERB
stash (third-person singular simple present stashes, present participle stashing, simple past and past participle stashed)
- To hide or store away for later use.
He stashed his liquor in the cabinet under the bar.
1. THE FOURTH SPACE
- there are 4 spaces of git,
- the work happens usually between the three of them:
working area → index → repository - stash is the fourth area
- there is only 1 command to handle stash
git stash
- you have to be very explicit within the single command
- git stash is all yours — the data there will not change unless you really want to
- it is even more yours than the working area and isolated from the 3 main areas
- for example, say you want to work on something else
- …but, you have some work already staged within a branch
- → you can store all your changes in the stash and they will stay there and wait for you to pick it up
2. CREATE
git stash save --include-untracked
- save the current status by or just
git stash --include-untracked
- also include files that are not tracked and are entirely new. by default, stash ignores untracked files
- git takes all the data from working area and stage → add them to the stash
- aligns the data from working area and stage with the current commit
3. ACCESS
git stash list
- the stash is a multiple clibboard where you can store things for later
- each item gets a serial-id
▶ git stash list
stash@{0}: WIP on newMainMenu: 3179211 publish action executed and links updated
4. RECOVER
git stash apply
- without passing the name of the item, it applies it to the most recent one by default
5. POP
git stash pop
- this deletes the stash when recovering it
6. CLEAR
git stash clear
- run
git stash clear
to clean the entire stash
7. VSCODE EXTENSION
- Git Stash — Visual Studio Marketplace
- assign shortcuts for both the creation and the recovery