A Look Inside the .git Folder

Each of the dozens of git repos on your machine contains a .git folder. But you may have never thought about the details of its contents. You know that somehow the folder holds the history of every version of every file ever committed to the repository. You just don’t know how.

The contents are less mysterious than you think. For obvious reasons, git optimizes the contents of the .git folder for size and speed. So you can’t browse into it and see your files. The object files are all named after their guid, and the data is zlib compressed. But the structure and organization is documented and understandable.

I’m not going to go into a full explanation of the files here. Others, like Rob Richardson (blog, twitter) have explained it better than I ever will. It was Rob’s talk at CodeMash that helped me understand how the contents of the .git folder worked. I just created a graphic from the info he shared. Additional details are available at GitReady.com.

I’ll simply summarize by saying that the files can be grouped into five categories:

  1. Objects - (blue)These represent the files and changes. Objects can be further divided into commits, trees, and blobs.
  2. Refs - (red)These are human-readable files that organize the objects
  3. Logs - (green)These are used to quickly generate logs displayed to the user.
  4. Config - (light gray)There are files used to config git’s behavior
  5. Temp - (gray)These are temporary files for information that git needs to hold between command-line actions.

Here is Rob’s definitive guide to what is in the .git folder.

January 30, 2022 |
Tags : git

Comments Section

Feel free to comment on the post but keep it clean and on topic.

comments powered by Disqus

About Me

Eric Potter My name is Eric Potter. I have an amazing wife and 5 wonderful children. I am a Microsoft MVP for Developer Tools and Technologies, a Principal Architect for Core BTS in Ft. Wayne Indiana, and an adjunct professor for Indiana Tech. I am a humble toolsmith.

Microsoft MVP Award

pottereric.github.com