diff --git a/README.md b/README.md index 48d9123..87f0720 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_1097 TILs and counting..._ +_1098 TILs and counting..._ --- @@ -290,6 +290,7 @@ _1097 TILs and counting..._ - [Skip Pre-Commit Hooks](git/skip-pre-commit-hooks.md) - [Staging Changes Within Vim](git/staging-changes-within-vim.md) - [Staging Stashes Interactively](git/staging-stashes-interactively.md) +- [Stash A Single Untracked File](git/stash-a-single-untracked-file.md) - [Stash Everything](git/stash-everything.md) - [Stashing Only Unstaged Changes](git/stashing-only-unstaged-changes.md) - [Stashing Untracked Files](git/stashing-untracked-files.md) diff --git a/git/stash-a-single-untracked-file.md b/git/stash-a-single-untracked-file.md new file mode 100644 index 0000000..a26ae98 --- /dev/null +++ b/git/stash-a-single-untracked-file.md @@ -0,0 +1,36 @@ +# Stash A Single Untracked File + +If you want to stash everything in your work tree and untracked files, you can +run: + +```bash +$ git stash -u +``` + +If you want a bit more control over what gets stashed from the work tree, you +can interactively stash with `--patch` (or `-p`): + +```bash +$ git stash -p +``` + +Unfortunately, the two don't work together. + +```bash +$ git stash -u -p +Can't use --patch and --include-untracked or --all at the same time +``` + +So, if you'd like to stash a specific untracked file, you can instead formulate +a command like the following: + +```bash +$ git stash -u -- +``` + +This will stash just the specified untracked file and leave the rest of them as +they are. + +I found this useful when trying to test the setup of a new library. There was +an extra new file that I didn't think I needed. Stashing it temporarily gets it +out of the way without losing it.