divine
divine

Reputation: 4912

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

Upvotes: 1

Views: 137

Answers (2)

Ivan
Ivan

Reputation: 3184

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

Upvotes: 3

Djee
Djee

Reputation: 439

git stash will store you working directory checkout your branch git pop will apply your working directory to this checked out branch if f1 is the only not staged file it will pop up as it was before you stashed

Upvotes: 0

Related Questions