1

Let's say I'm working on a master branch that has file colors.txt:

blue
red
yellow

From there I create and switch to a new branch warm and edit the same file colors.txt to:

red
yellow
orange

I don't add those changes to Staging Area, but rather switch back to master branch => GIT doesn't complain.

What I expected instead is message: "Please commit your stages or stash them before you switch branches".

Can someone tell me how did this example succeed and why am I not getting that error message I just described?

Stefan
  • 969
  • 6
  • 9
  • 1
    https://stackoverflow.com/a/28257995/7976758 Found in https://stackoverflow.com/search?q=%5Bgit%5D+checkout+expected+conflict – phd Aug 14 '21 at 17:21

1 Answers1

1

The message you expect would only occur if your changes could not be applied to the master branch because it conflicts.

Otherwise uncommited changes do are kept when switching branches.

The important thing is you will never loose the changes, either you will be asked to commit/stash them before switching branch or they will be kept in the branch you switch to.

Gaël J
  • 11,274
  • 4
  • 17
  • 32
  • Can you tell me why would any changes not be applied to the `master` branch? – Stefan Aug 14 '21 at 17:32
  • In your specific case it cannot happen. But it could happen if you created the other branch before and some commits were done in the mean time to `master`. – Gaël J Aug 14 '21 at 17:33