Search code examples
gitphpstorm

Changes from one branch are also applied (kept) in other branches? (PhpStorm & Git)


I'm using PhpStorm 2018.2.4 (Ubuntu 18).

Let's say that I've pulled the develop branch from GitHub repo (project) and there are 2 files in the project:

  • file_1.php
  • file_2.php

Then I create a new branch in PhpStorm named feature/something and checkout ( in the Branches popup, I choose New Branch, select Checkout branch option and enter name ... ).

Now I'm on feature/something.

I do some changes in file_1.php and in the PhpStorm's file browser it becomes blue (as expected).

BUT, when I go (checkout) back to develop branch - the changes I've made when I was on feature/something are kept (are also applied) on develop branch:

  • file_1.php is still 'blue'
  • changes in file_1.php are there...

Is this supposed to work like that OR when I move back (checkout) to develop branch - the changes from feature/something should not be applied (kept) in develop?

  • If this is normal - then how can I move back to the "original" (clean) develop (without the chages from the other local branch)? If I do revert while on develop - then when I move (checkout) back to the feature/something - those changes were reverted there too.

  • If this is not supposed to work like this, how can I fix it?


Solution

  • As long as you don't commit those changes, the changes are kept irrespective of the checked out branch. If checking out another branch would conflict with those changes, Git would tell you that. So, stage and commit the changes on your feature branch if you want to keep them. If you then check out develop, it won't show those changes.

    See also Checkout another branch when there are uncommitted changes on the current branch.