Search code examples
gitgit-stash

Git - what stash command does?


In which scenario stash command should be used ?

1) Let's assume i have a branch(b1) and there is a file(f1) that i haven't staged. When i create a new branch(b2) from branch(b1), my file(f1) wouldn't be available in the new branch(b2).

2)But if i had staged file(f1) in branch(b1) then file(f1) would be available in the new branch(b2) because the file(f1) isn't commited yet. This should not happen and that is why we use stash command?

Please correct me if this is wrong and provide additional informations related to stash


Solution

  • For my opinion, the most "classic" scenario for stash usage:

    • you work on branch Bug-X
    • the fix is not done, but you should resolve very urgent Bug-Y
    • you stash your changes for "Bug-X"
    • checkout Bug-Y, fix, commit, push
    • checkout Bug-X
    • unstash and continue to work