E.Omar's answer is correct (and upvoted), but it's worth emphasizing that your work-tree—the place where you see, and work with, your files—is not a branch. It is not a commit, and it will not be preserved! It is merely the place where you do your work.
What will be preserved—forever, or as long as the commit itself exists, anyway—is the complete snapshot that you make when you make a new commit. But this snapshot is not a copy of your work-tree at all! Instead, it is a snapshot of what you put into Git's index.
The index—which is also called the staging area or sometimes the cache—is a complicated thing, but it is, I think, best thought of as: All the files that Git will put into the next commit that you make, when you make it. It starts out being a copy of all of the files saved in the commit that you checked out when you ran git checkout name
.
If you create a new file in your work-tree, or after you have modified an existing file, nothing has happened to the index. It's still a copy of what was in the commit. Running git add
tells Git to copy the file from the work-tree into the index, making it ready to go into the next commit. Until then, it's just a file in the work-tree: an untracked file, if there's no copy of it in the index.
See also the answer that phd linked-to in a comment on the question Modified files in a git branch are spilling over into another branch (which we've used as a duplicate for a closer for this question). Note that causing the new file to become tracked (by git add
-ing the new file) is not sufficent: you must also run git commit
to make a new commit that contains a frozen-forever copy of the file (plus, of course, all the other files). Until then, it's just an untracked or tracked file, but not in any commit.