title: Explanation of how Git checkout works
body: <p>I am using the default bash that comes with Git, I made a master branch (not bare) and made a branch (lets call it new_feature branch) out of it.</p>
  
  <p>I am playing around with branching and I get to the point where I am testing the <code>git checkout</code> command. As I have understood, the checkout command allows switching from one branch to another. Also from what I understood, the checkout command doesn't allow you to switch from one branch to another if the working directory is dirty (i.e. has unstaged edits).</p>
  
  <p>Now I have a file named <code>index.html</code> in both my main branch and my feature branch. Both the files in the 2 branches have exactly the same content. Now here is what I did, and it made me confused.</p>
  
  <p>I am on my feature branch (currently both files have exact same content now), if I edit the content of <code>index.html</code>, say the title tag, and I did not staged it, if I issue the command <code>git checkout master</code>, Git does allow me to switch to the master branch, and what's more interesting is that if I issue the <code>git status</code> command within the master branch, the unstaged changes I made on the feature branch gets copied to the master branch. Isn't it destructive?</p>
  
  <p>What made me more confused is, in a given time where the 2 files on both the branches, master and feature branch, doesn't have the same content, if I'm inside the feature branch and edit the content of the <code>index.html</code> file, say the title tag, now if I issue the <code>git checkout master</code> command, it don't allow me to make the switch because it detected that my working tree or directory is dirty.</p>
  
  <p>Bottom line, as I have noticed based on these events, if 2 files have the same content, if you are in one branch, modify the content of that file, and checkout to that other branch, Git allows you to make the switch, and Git carries the unstaged changes you made to that destination branch.</p>
  
  <p>But if 2 files on 2 different branches have different content, if you are on one branch, made the edit to that file, and issue the checkout command to switch to that other branch, Git doesn't allow you to make the switch because for some reason it detects that the working tree is dirty.</p>
  
  <p>Is my understanding correct or wrong? Also I can use a little explanation as to why my understanding is wrong or correct.</p>