Patricio Treviño · 13 November, 2018 · 4 min read
Stash all changes in a git repository
Syntax
|
# stash everything (tracked, untracked, ignored) |
|
git stash --all |
|
|
|
# stash everything, (tracked and untracked, but not ignored) |
|
git stash [save -u | --include-untracked] |
Example
With git stash --all
|
# adds a new file |
|
$ touch file.txt |
|
|
|
# update .gitignore to include file.txt |
|
$ "file.txt" > .gitignore |
|
|
|
# get the status |
|
$ git status |
|
On branch master |
|
Your branch is up to date with 'origin/master'. |
|
|
|
Changes not staged for commit: |
|
(use "git add <file>..." to update what will be committed) |
|
(use "git checkout -- <file>..." to discard changes in working directory) |
|
|
|
modified: .gitignore |
|
|
|
no changes added to commit (use "git add" and/or "git commit -a") |
|
|
|
# stash changes (stashes .gitignore and file.txt) |
|
$ git stash --all |
|
|
|
# get the status |
|
$ git status |
|
On branch master |
|
Your branch is up to date with 'origin/master'. |
|
|
|
nothing to commit, working tree clean |
With git stash --include-untracked
|
# adds a new file |
|
$ touch file.txt |
|
|
|
# update .gitignore to include file.txt |
|
$ "file.txt" > .gitignore |
|
|
|
# get the status |
|
$ git status |
|
On branch master |
|
Your branch is up to date with 'origin/master'. |
|
|
|
Changes not staged for commit: |
|
(use "git add <file>..." to update what will be committed) |
|
(use "git checkout -- <file>..." to discard changes in working directory) |
|
|
|
modified: .gitignore |
|
|
|
no changes added to commit (use "git add" and/or "git commit -a") |
|
|
|
# stash changes (stashes .gitignore, file.txt becomes available as it's no longer ignored) |
|
$ git stash --include-untracked |
|
|
|
# get the status |
|
$ git status |
|
On branch master |
|
Your branch is up to date with 'origin/master'. |
|
|
|
Untracked files: |
|
(use "git add <file>..." to include in what will be committed) |
|
|
|
file.txt |
|
|
|
nothing added to commit but untracked files present (use "git add" to track) |
References
Stackoverflow: How do you stash an untracked file?