git – How can I save changes to my branch and switch to another branch without committing?


It is possible that I have several branches


And for example, I have changes in foo , but I want to go to bar , but WITHOUT committing the changes in foo , is there any way to save them "temporarily" without needing them to appear in the commit history?


You can use git stash to push the commit changes, then move to another branch and when you're done on that other branch doing what you had to do, you can go back to the original branch and do git stash apply .

The flow would be like this:

  • You are in branch develop and you have comiteados changes
  • git stash
  • git checkout master
  • You do what you have to do in master
  • git checkout develop
  • git stash apply
  • Everything stays in develop as if nothing had happened

More information about git stash here .

Scroll to Top