How the working directory is updated on "git checkout"?

Git checkout (loosely) will update the working copy with the contents of the repository at the commit which specify. Your new_feature branch doesn't have the second line which you've added to your file (since you haven't committed it yet). Right now, that extra line is just an untracked change in your working copy and it will get added to the branch on which you commit it.


Your git checkout to master prevents you from losing uncommitted changes. Thats why you still have your second line in your hello.txt file. If you really want to lose your uncommitted changes you have to use the -f parameter.

Finally your checkout would look like this:

git checkout -f master