Stashing individual files in Git
Stashing is a very useful feature in Git. It allows you to temporarily save your changes in a stash and then apply them later. This is very useful when you want to switch to another branch but don’t want to commit your changes yet. You can stash your changes and then apply them later.
However, sometimes, you may want to stash only a few files and not all of the files. For example, you may want to stash only the app.js
file and not the app.css
file. I recently learned that you can stash individual files in Git.
Essentially, you can use the git stash push
command to stash individual files. For example, you can stash the app.js
file individually like so.
$ git stash push app.js
This will stash only the app.js
file and not the app.css
file. You can also stash multiple files like so.
$ git stash push app.js app.css
You use the
git stash push -p
command to stash individual files interactively.
You can also add a message to the stash by using the -m
option like so.
$ git stash push -m "Stashing app.js" app.js
Like this article?
Buy me a coffee👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.