Vannkorn

Full Stack Web Developer

Close

Git Stash and Git Stash Pop

Git stash is useful when you work on different branch at the same time.

Ads: Register now via this link to receive $300 credit from Vultr

Today I’ve learned a great Git feature that allows me to save my changes in the current branch so that I can switch to another one and make changes there.

Another useful situation is when we pull the changes from the remote branch while those changes conflict with our local changes. Instead of fixing the conflict or reverting back the changes, git stash allows me to save my changes so that I can revert back the changes and pull the changes from the remote repository. After the pull completes, we can use the git stash pop to load the changes that I have saved before. This is super useful.

Below is an example of the case:

  1. Save changes to branch A.
  2. Run git stash.
  3. Check out branch B.
  4. Fix the bug in branch B.
  5. Commit and (optionally) push to remote.
  6. Check out branch A.
  7. Run git stash pop to get your stashed changes back.

Leave a Reply

Your email address will not be published. Required fields are marked *