Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There's something I don't understand about how git manages files when changing branches:

When I run

git branch xxx

What does happen to the existing physical files? Are they being moved? Deleted? Stored in a DB? Do git involve a filesystem magic?

share|improve this question
If you want to learn about the low level magic of git, I highly recommend "Git from the bottom up": – WakiMiko Jul 22 '12 at 13:00

When you run git branch xxx, Git only creates the new branch, but doesn't actually switch to it – the working tree is not modified at all. (Note that the new branch will have exactly the same files and history as the old one.)

When you run git checkout xxx to switch branches, files belonging to the old branch are simply deleted from the working tree and replaced with ones from the new branch.

Remember that every time you commit, Git stores the "master copy" of all commited files in the .git directory. When you browse the history or switch branches, Git looks inside this directory.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.