Skip to content

Commit 5f20629

Browse files
committed
Add Stash A Single Untracked File as a git til
1 parent 3658b4d commit 5f20629

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
1212

13-
_1097 TILs and counting..._
13+
_1098 TILs and counting..._
1414

1515
---
1616

@@ -290,6 +290,7 @@ _1097 TILs and counting..._
290290
- [Skip Pre-Commit Hooks](git/skip-pre-commit-hooks.md)
291291
- [Staging Changes Within Vim](git/staging-changes-within-vim.md)
292292
- [Staging Stashes Interactively](git/staging-stashes-interactively.md)
293+
- [Stash A Single Untracked File](git/stash-a-single-untracked-file.md)
293294
- [Stash Everything](git/stash-everything.md)
294295
- [Stashing Only Unstaged Changes](git/stashing-only-unstaged-changes.md)
295296
- [Stashing Untracked Files](git/stashing-untracked-files.md)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Stash A Single Untracked File
2+
3+
If you want to stash everything in your work tree and untracked files, you can
4+
run:
5+
6+
```bash
7+
$ git stash -u
8+
```
9+
10+
If you want a bit more control over what gets stashed from the work tree, you
11+
can interactively stash with `--patch` (or `-p`):
12+
13+
```bash
14+
$ git stash -p
15+
```
16+
17+
Unfortunately, the two don't work together.
18+
19+
```bash
20+
$ git stash -u -p
21+
Can't use --patch and --include-untracked or --all at the same time
22+
```
23+
24+
So, if you'd like to stash a specific untracked file, you can instead formulate
25+
a command like the following:
26+
27+
```bash
28+
$ git stash -u -- <name-of-untracked-file>
29+
```
30+
31+
This will stash just the specified untracked file and leave the rest of them as
32+
they are.
33+
34+
I found this useful when trying to test the setup of a new library. There was
35+
an extra new file that I didn't think I needed. Stashing it temporarily gets it
36+
out of the way without losing it.

0 commit comments

Comments
 (0)