title: Changing branches does not discard local changes
body: <p>So, I'm a bit confused.</p>
  <p>I'm not very good on git, but I remember that if you're in a branch with uncommited changes and you try to checkout another branch, git will either don't let you, or it will discard your changes.</p>
  <p>I've also checked this behaviour to be true in the Apress' &quot;Pro Git&quot; book by Chacon and Straub.</p>
  <p><a href="https://i.stack.imgur.com/dSLEQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dSLEQ.jpg" alt="enter image description here" /></a></p>
  <p>And also</p>
  <p><a href="https://i.stack.imgur.com/Baciy.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Baciy.jpg" alt="enter image description here" /></a></p>
  <p>I confess my English isn't very good, but I remember this interpretation to be true from the old days were I used to use git more often. Or did I'm wrong about git discarding uncommited changes when changing branch? Am I understanding what the book is saying wrongly?</p>
  <p>If I'm right, why do my repository is moving changed files from one branch to another? You can check the behaviour here:</p>
  <p><a href="https://i.stack.imgur.com/dj9dS.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dj9dS.jpg" alt="enter image description here" /></a></p>
  <blockquote>
  <p>Check that I'm in main branch and that it's clean from changes using <code>git status</code>.</p>
  </blockquote>
  <blockquote>
  <p>Create a new branch and move to it.</p>
  </blockquote>
  <blockquote>
  <p>Do some random alterations like deleting a couple of lines using <code>ed</code>.</p>
  </blockquote>
  <blockquote>
  <p>Change back to main branch.</p>
  </blockquote>
  <blockquote>
  <p>Surprise, a <code>git diff</code> or a <code>git status</code> shows that the file is changed on main as well.</p>
  </blockquote>
  <p>Should not git prevent me changing branch or discard my changes instead? This is very confusing and took me a while to realize why my main branch was having unexpected behaviour if I didn't changed anything on it.</p>
  <p><code>git version 2.30.1 (Apple Git-130)</code></p>
  <hr />
  <p><strong>Edit</strong>: Some answers said about <code>git switch</code> being different than <code>git checkout</code>. I'm still not sure that's the case since different people (and docs) says different things.</p>
  <p>But, I've also tried the same using <code>git checkout</code> and it will also move the files instead of preventing me to switch or warning me about differences in the working directory.</p>
  <p>You can see <code>git checkout</code> doing the same as follow:</p>
  <p><a href="https://i.stack.imgur.com/vbdMR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vbdMR.png" alt="enter image description here" /></a></p>