Search code examples
gitgit-commitgit-stash

GIT: Do I need to commit my branch before checking out another branch, what about stashing?


I'm new to Git and a bit confused. I have a Master branch and have created a second feature branch.

If I make changes in my feature branch and then switch to Master, will my changes be lost if I don't commit?

Where does stash come into play, is it something you do before you switch branches (but don't want to commit) or is it to simply revert some changes so you can get back to previous code temporarily?


Solution

  • You can't change to another branch unless you clean your tree. This is done by committing your changes, reverting them or saving them to the stash.