Git Stash
We use git stash
to store our changes when they are not ready to be committed
and we need to change to a different branch.
-
Stash:
git stash save # or git stash # or with a message git stash save "this is a message to display on the list"
-
Apply stash to keep working on it:
git stash apply # or apply a specific one from out stack git stash apply stash@{3}
-
Every time we save a stash it gets stacked so by using
list
we can see all our stashes.git stash list # or for more information (log methods) git stash list --stat
-
To clean our stack we need to manually remove them:
# drop top stash git stash drop # or git stash drop <name> # to clear all history we can use git stash clear
-
Apply and drop on one command:
git stash pop
- If we meet conflicts we need to either reset or commit our changes.
- Conflicts through
pop
will not drop a stash afterwards.
Git Stash sample workflow
- Modify a file
- Stage file
- Stash it
- View our stash list
- Confirm no pending changes through status
- Apply with pop
- View list to confirm changes
# Modify edit_this_file.rb file
git add .
git stash save "Saving changes from edit this file"
git stash list
git status
git stash pop
git stash list
git status
Help and feedback
If there's something you don't like about this feature
To propose functionality that GitLab does not yet offer
To further help GitLab in shaping new features
If you didn't find what you were looking for
If you want help with something very specific to your use case, and can use some community support
POST ON GITLAB FORUM
If you have problems setting up or using this feature (depending on your GitLab subscription)
REQUEST SUPPORT
To view all GitLab tiers and features or to upgrade
If you want to try all features available in GitLab.com
If you want to try all features available in GitLab self-managed
If you spot an error or a need for improvement and would like to fix it yourself in a merge request
EDIT THIS PAGE
If you would like to suggest an improvement to this doc