Git stash has many common operations that can be represented by following commands.

git stash
git stash list
git stash pop [–index] [stash_id]
git stash apply [–index] [stash_id]
git stash drop [stash_id]
git stash clear

Now we will learn a few other powerful options.

git stash push

After October 2017, the command git stash save has been deprecated in favor of the alternative git stash push because git stash push has the option pathspecs but git stash save does not support.

We can use the command to handle a few files rather than all changed and tracked files. git stash save always handles all changed files which are tracked, so git stash push is smarter.

git stash push -m "save only progress"

git stash --keep-index

It stores the staged files and changed contents in the stash stack simultaneously.

$ git status

$ git stash --keep-index
Saved working directory and index state WIP on master: ca052c9 Update

$ git st

git stash -u

-u means --include-untracked.
It supports to include files which are not tracked in the stash being created.

$ git st

Untracked files:

$ git stash -u
Saved working directory and index state WIP on master: ca052c9 Update

$ git st
nothing to commit, working tree clean

git stash branch <branchName>

The command git stash branch support to create a new branch which contains the last commit and stashed contents, then it drops the stash if it applied successfully.
1. change files.
2. git stash
3. git stash branch <branchName>
4. review the change and commit to the new branch.
5. go back old branch, we can merge the new branch.

$ git stash push -m "save"
Saved working directory and index state On master: save

$ git stash branch test1
Switched to a new branch 'test1'
On branch test1

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/[email protected]{0} (c73709950b50d1be86a9c6ff87a3ff1cbdf7cace)


git stash all: it can remove everything from our working directory even if the files are not tracked.
git stash -p: --patch/-p can help us to include a part content in stash stack. Relevant article: Interesting Option -P For Git Command

Categories: Tool

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments

3D Files Converter: Support to write X3D file and VRML file.

A prohibited operation
Would love your thoughts, please comment.x