If I create a new branch from master, then make some changes, if I don't commit the changes and then checkout master, my changes follow me back to master. I don't get it... If I commit the changes in the new branch and then checkout master, then master remains unchanged. Isn't this a recipe for making unwanted changes in master? What is the proper workflow here?
git init
echo something > newfile
git add newfile
git commit -a -m "first commit"
git checkout -b dev
echo $(date) >> newfile
git checkout master
[user@toolbox test]$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: newfile
no changes added to commit (use "git add" and/or "git commit -a")
[user@toolbox test]$ cat newfile
something
Thu 26 Sep 2019 09:00:49 PM GMT
[user@toolbox test]$
But...
[user@toolbox test]$ git checkout -- newfile
[user@toolbox test]$ git checkout dev
Switched to branch 'dev'
[user@toolbox test]$ git commit -a -m "I dont get this"
On branch dev
nothing to commit, working tree clean
[user@toolbox test]$ git checkout master
Switched to branch 'master'
[user@toolbox test]$ git status
On branch master
nothing to commit, working tree clean
[user@toolbox test]$ cat newfile
something
[user@toolbox test]$
I was expecting that "checkout" just switches branches. But obviously there is something I don't understand about the git workflow.