Search code examples
gitphpstorm

How to correctly switch between branches in PHPStorm?


So the problem is, I've made a new branch: myname/mysuperbranch

And at the same time I have origin/master branch. And after I've made changes to my branch I checkout back to origin/master and it still has all my changes that I made inside of the myname/mysuperbranch branch.

How do I correctly switch between branches? For example:

  1. I made some changes in my myname/myspuerbranch

  2. Save this changes locally.

  3. Switch to origin/master branch, and it should be clean, without any changes.

What am I doing wrong?


Solution

  • When you make changes and simply switch the branch you will have the see the same changes in the other branch. You actually have to commit them first so the changes are on the staging area.

    VCS > Git > Commit File...

    Or even push it to a remote branch. After your changes are on the staging area the branch will differ from your master when you switch back. Of course the files have to be added to your working directory first. Normally PHPStorm will add newly created files automatically. Otherwise simply rightclick them.

    Git > + Add