Using git on mac (sierra); git version 2.8.4 (Apple Git-73)
git checkout <master>
git clone -o origin -b master firstname.lastname@example.org:prj/PRODUCTION.git
git branch -b new_branch
git checkout new_branch
<make changes to an existing file>
git checkout master
This is the expected behavior, and is what I normally see when using Git. From the documentation for git checkout:
To prepare for working on <branch>, switch to it by updating the index and the files in the working tree, and by pointing HEAD at the branch. Local modifications to the files in the working tree are kept, so that they can be committed to the <branch>.
If you need to switch branches and your working directory is not clean, here are a couple of options:
1) you can make a temporary commit on your current branch:
git commit -m 'WIP'
I say "temporary" but really this is just like any other commit. The only difference is that when you return to this branch you will amend this commit once you have finished the task via:
git commit --amend -m 'Finished WIP'
2) Stash away your changes via
Stashing will create two commits, one for the working directory and one for the stage. When you want to bring these changes back you can apply these changes via:
git stash apply