brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: stash your new files too with git stash -u

Git
~/tips/tip-git-stash-include-untracked

git stash push -u -m "login form, half done"

Stashes your changes together with new files that git does not track yet, and labels the stash.

A plain git stash leaves a nasty surprise behind: the files git has never seen before stay right where they are.

By default the stash only takes changes to files git already tracks. Brand new files are not touched, so your tree is not as clean as you thought. Add -u (long form --include-untracked) and the untracked files go into the stash too. The docs say they are then cleaned up with git clean.

git stash push -u -m "login form, half done"
git stash list
git stash pop

Here I also gave the stash a name with -m. Without it, the stash is listed as "WIP on" plus the branch name, and after a few of those you will not know which one is which.

You can peek inside before you pop. git stash show -p shows the stash as a diff, and with -u it includes the untracked files as well.

The caveat: files that are in your .gitignore are not part of this. And because the new files really disappear from disk, do not forget the stash exists. If a file is suddenly missing, run git stash list first.

Further reading: git stash documentation, On this site: preview what git clean will delete with -n, On this site: git diff –staged shows what your commit will contain

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link