DEV Community

Caleb Hearth
Caleb Hearth

Posted on • Originally published at calebhearth.com on

How to Stash Everything git commit Wouldn't Commit

Sometimes I want to take some changes that I’ve made but haven’t yet committed yet and put the into the git stash, which I probably use a lot more than I should. When will you learn to just git commit -mwip, Caleb?

Either way, Git has my back. git stash --keep-index --include-untracked is almost the opposite of the above. It creates a stash commit for only files that wouldn’t otherwise be committed: unstaged changes and untracked files.

  • --keep-index leaves all changes already added to the index (i.e., staged) intact
  • --include-untracked stashes files in the working tree that have not yet been tracked by Git, and then runs git clean to remove untracked files

The above command is really useful in cases when you want to make a commit of a subset of your working tree. Say you’ve set up the perfect commit and want to run your tests to be sure that it works or you’re about to switch branches but want to take some changes with you.

It occurs to me that this would be a good alias. Maybe I...

Read more

Top comments (0)