0

My project has 2 branches:

* master
* A

I created branch B from branch A by git checkout -b B A. After that, I made some changes in B, however those changes also appear in branch A.

Is that a normal behavior of Git? What should I do if I want changes in B don't appear in A?

For more detail, I didn't commit the changes in B; and checkout to A show the changes.

Joey
  • 111
  • 8
  • 1
    That's not how branch works. If you commit your change in branch B they will not be visible in branch A. For these changes to be visible in A, you must first merge branch B in A. To better understand your problem, you need to write exact commands you've run, show their outputs and explain what are the symptoms that make think this unexpected behaviour is occuring. – davidriod Jan 06 '23 at 08:05
  • 5
    Did you *commit* your changes on `B`? Because if not, it's expected that your changes are still here after you switch. Asking just in case. – Romain Valeri Jan 06 '23 at 08:05
  • @RomainValeri No I didn't commit it. – Joey Jan 06 '23 at 08:07
  • 2
    [this](https://stackoverflow.com/a/67823541/11261546) might answer your question :) – Ivan Jan 06 '23 at 08:10
  • 2
    Great catch, @RomainValeri! :+1: I would have assumed that the OP was talking about _committed_ changes right off the bat. – eftshift0 Jan 06 '23 at 08:29

1 Answers1

1

As @RomainValeri mentioned above, since I didn't commit the changes, it's the default behavior of Git to show these changes when I switch to another branch.

Joey
  • 111
  • 8