Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

Stashing individual files in Git

December 29, 2022 ·

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

👋 Hi there! I'm Amit. I write articles about all things web development. If you like what I write and want me to continue doing the same, I would like you buy me some coffees. I'd highly appreciate that. Cheers!

Comments?