How to stash specific files in Git

Stashing specific files in Git allows selective temporary storage of changes while preserving other modifications in the working directory. With over 25 years of experience in software development and as the creator of CoreUI, I’ve used selective stashing extensively when managing multiple feature developments and experimental changes simultaneously. From my expertise, the most effective approach is using git stash push with specific file paths to stash only the desired files. This technique provides granular control over which changes to temporarily store while continuing work on other modifications.

Use git stash push with file paths to stash only specific files while keeping other changes in the working directory.

git stash push -m "Stash only CSS changes" src/styles.css src/components.css

Here git stash push followed by file paths stashes only the specified files, while --message or -m adds a descriptive message for easy identification. The command stashes changes in the specified files and reverts them to the HEAD state, while leaving all other modified files untouched in the working directory. This allows selective management of different sets of changes without affecting unrelated work in progress.

Best Practice Note:

This is the same approach we use in CoreUI development when we need to temporarily stash CSS changes while continuing work on JavaScript functionality, or when isolating specific feature changes. Always use descriptive messages with selective stashes to easily identify and retrieve the correct changes later using git stash list.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author