If you did not commit files to a branch, they are not in the branch. If you just did git add
, then you staged those files. They are tracked by branches in any way. If you switch branches with some files staged, they will still be staged. It always worked this way as long as I can remember.
ORIGINAL ANSWER (for reference)
You must be doing something wrong. You didn't share all your commands, most notably the commits and how you display the content of branches. But consider this:
$ git init /tmp/test1
$ cd /tmp/test1
$ touch hello.txt
$ git add .
$ git commit -m added
[master (root-commit) 12778a0] added
0 files changed
create mode 100644 hello.txt
$ git checkout -b halo
Switched to a new branch 'halo'
$ touch halo.txt
$ git add halo.txt
$ git commit -m 'added halo'
[halo 9a2b380] added halo
0 files changed
create mode 100644 halo.txt
$ git checkout master
Switched to branch 'master'
$ git ls-files
hello.txt
$ git ls-files --with-tree halo
halo.txt
hello.txt
Everything works as intended. This is in Git 1.7.10.4
There was one mistake in your commands:
git branch -b halo
At least in my version git branch
doesn't have a -b
option. I assume you meant git checkout -b halo
so that's what I used above.