I clearly do not understand git at all. This is what I'm getting:
git branch (outputs that I'm on master)
git checkout -b foo
echo "next line" >> file (file is an existing file)
git add file (stages)
git checkout master
git status (shows that file has "next line" and is staged!!)
git commit (commits the changes that were staged on branch foo!!)
git checkout foo
Here is the kicker. foo now doesn't show any changes made to file in the working directory OR staged.
So looks like - any changes you make, including modifying files and staging, happen to ALL branches. and when you COMMIT to a specific branch, those changes are discarded on all other branches except the one you committed on.
Is this actually what is going on? Can someone make this make sense to me? It sounds like completely screwy behavior and clearly I don't get the design idea that makes this a sensible thing to do.
Edit for explicit example:
$ mkdir element
$ cd element
$ git init
Initialized empty Git repository in /home/dan/element/.git/
$ echo "one" >> one
$ git add one
$ git commit -m msg
[master (root-commit) 36dc8b0] msg
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 one
$ git checkout -b fire
Switched to a new branch 'fire'
$ echo "next line" >> one
$ git checkout master
M one
Switched to branch 'master'
$ cat one
one
next line
$
Which patently contradicts this from the git pro book:
This is an important point to remember: Git resets your working directory to look like the snapshot of the commit that the branch you check out points to. It adds, removes, and modifies files automatically to make sure your working copy is what the branch looked like on your last commit to it.