If you are juggling branches and you added new files that are not yet tracked, you do not have to choose between losing work and creating a messy commit. Git stash can hide those new files while you switch branches and then bring them back when you are ready. This guide shows the exact commands and a few survival tips so your future self does not curse you.
Before hiding anything use the command line to check the situation. That way you know which files are tracked and which ones are fresh and untracked.
git status
git status lists modified tracked files and new untracked files by name. No guessing, no panic.
The default stash only saves tracked changes. If you want to stash new files as well use the untracked flag. For example this will save tracked edits and new files that are not ignored.
git stash push -u -m "WIP untracked"
If you also want to stash ignored files for a moment use the all flag. Handle that with care because ignored files are ignored for a reason, usually to keep secrets or noise out of source control.
git stash push --all -m "WIP including ignored"
Stashes are cheap and reversible but it is polite to check what you stashed before you start applying stuff. The stash list shows entries and their messages. The stash show command gives a quick diff preview so you can confirm the right files were captured.
git stash list
git stash show -p stash@{0}
Pick your favorite method. If you want the stash to remain available use apply. If you want to reapply and remove the stash use pop. Either way you can handle conflicts the same way you handle regular merge conflicts.
git stash apply stash@{0}
git stash pop
git stash drop stash@{0}
Check status, stash with -u if you need new files saved, inspect the stash, then git stash apply or git stash pop to recover. Drop the stash when you are done to keep the list tidy and your repo from becoming a graveyard of old experiments.
Now go do the thing you needed to switch branches for and try not to forget you stashed stuff. If you do forget it at least you have a good excuse the next time your teammates ask where that file went.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.