14

Just found out the beauty that is "git stash -u". This stashes all your changes, even the untracked ones. Why the hell isn't this the default?

Comments
  • 0
    As someone new to git, what's an average use for this?
  • 1
    @logicbomb421

    1. You want to pull latest code without merging.

    2. You have some local project files (which for some reason your team tracks) and gets modified just from viewing a project, so doing a git pull will fail until you commit changes you don't really want to commit. git stash hides all changes so a pull can be done.

    3. Your project references a large external library that isn't checked into version control. So everyone's workspace reference is different, but part of your project knows the reference exist somewhere and wants to points to an invalid directory by default. You don't want to break your local references just for grabbing the latest code, so you git stash, pull the fresh new code and default reference, the pop your stashed workspace file to restore your local references.

    git stash -u helps when a git pull can result in clobbering untracked files. Untracked files may not be important for version control, but they are important to your local IDE and workspace.
  • 0
    @logicbomb421 I find it useful when I'm working on new functionality and suddenly have to switch branches.

    Usually when you're just editing files you can use "git stash" to store all changes you've made, but when introducing new files that doesn't work. With "-u" it will store these new files as well. This is particularly handy if you don't want to track those files yet, because you want to check the diff for them or something.
Add Comment