Git is a distributed version control system. At the heart of Git's powerful capabilities lies its object model. Understanding Git's object model is important for mastering its use and leveraging its full potential. This article will dive deep into the components of the Git object model, explaining how each part functions and contributes to the system's efficiency.
When we work with git, the first command that we use to initialize our repository to git repository is the git init command. After using this command, we can see that the .git folder is created. Let's get deep dive into the folder and see what all we have got in the .git folder.

Git, a distributed version control system, has revolutionized how developers manage and track changes in their projects. At the heart of Git's powerful capabilities lies its object model. Understanding Git's object model is crucial for mastering its use and leveraging its full potential. This article will dive deep into the components of the Git object model, explaining how each part functions and contributes to the system's efficiency.
We can see that we have many subdirectories in the .git folder, but the subdirectory that we would have a look at is the .git/objects subdirectory. Generally, the objects folder consists of four different types of objects - blob, tree, commit and tag.
.git/objects directory is empty as of now but we will see some changes in it and we will understand why this directory is important to us. In Git, every commit, every tree, and every file is saved in the objects folder as a hash value. There is a unique hash value for every object which helps Git to where it is located. The folders are created accordingly. We will learn about hashes as we move forward. Since the objects folder is empty as of now, let's create a file demo.txt and write "Hello Geeks" in it.
We are using Ubuntu here but Windows users can work with the git bash . Ubuntu Commands can be run on git bash.

Now, let's add our changes to the staging area and commit our changes by using -
git add demo.txt
git commit -m "First Commit"

Let us observe changes in our objects folder after this command.

So we got new directories which are named 2 characters long and have 38 characters long file name.
Note: You might have different hashes in your computers so no need to worry if you don't get the same hashes.
Git generates a 40-character checksum (SHA-1) hash for every object and the first two characters of that checksum are used as the directory name and the other 38 as a file name.
Therefore the 40 character hashes that we have are -
6d510f79378ca9954e1078a70ff4fdaaa64494fe
7c5d8f39237365acdf66527189ba4fbb6c59b4fc
893f819f4a3b12c76aec907ad636edff48ffcfad
Let us now check what are these 3 different objects and their types. We will use the command - git cat-file

However , the command that we would be needing are -
- git cat-file -t <hash value> // used for showing type of object
- git cat-file -p <hash-value> // used for showing content of object
Let us check the type of our objects -
git cat-file -t <40 character hash value> //checks the type of the object

So, the types that we have got are - blob, tree, and commit. Let us understand them in more detail.
1. Blob Object
Blob - Binary Large Object
Blob stores the contents of the file. Whenever we commit our files the first type of objects that are created are the blob objects. Let us have a look at the content of our blob object with the help of -
git cat-file -p <blob object hash value>

We can see that we got the content of our file demo.txt that we wrote initially i.e Hello Geeks.
2. Tree Object
Tree objects contain a list of all files in our repository with a pointer to the blob object assigned to them. Let us have a look at the content of our tree object with the help of -
git cat-file -p <tree object hash value>

Each line in a Tree object has - file permissions, object type, object hash, and filename. Let us break down the line -
File Permission (100644) - Permissions of 644 means that the owner of the file has read and write access, while the other users on the system only have read access. blob represents the type of object. 40 character hash represents the hash of the object. You can verify it with your blob hash. demo.txt represents the filename.
3. Commit Object
Git creates a commit object that has a pointer to its tree object. The commit object contains - tree object hash, parent commit hash, author, committer, date, and message. Let us have a look at the content of our commit object with the help of -
git log
git cat-file -p <commit object hash value>

As clear from the above image, the commit object consists of - Tree object, Name of the author, Name of the committer, and the commit message. Since we have covered 3 different types of objects, we are left with one i.e Tag Object.
4. Tag Object
A tag object contains an object name, object type, tag name, the name of the person who created the tag, and a message. Let us make an annotated tag using -
git tag -a "first-tag" -m "Tag For First Commit"

Let us now check our objects folder to see whether the tag object is created or not.

We can see that a new directory "97" is being added. Let us now verify our type and see the contents of our tag object.
git cat-file -t <tag object hash value>
git cat-file -p <tag object hash value>

We can see that the tag object is pointing to the commit object (verify using our commit hash value) as we expected. I hope you would have found this article useful. We have covered all four object types and you can try more by doing some changes and repeating above the steps again.
Similar Reads
Object Model in Java
The object model is a system or interface which is basically used to visualize elements in terms of objects in a software application. It is modeled using object-oriented techniques and before any programming or development is done, the object model is used to create a system model or an architectur
8 min read
Git Security Model
Git is one of the most popular version control systems, used by developers and non-developers for tracking changes, collaborating on projects, and managing codebases. While Git is popular for its efficiency in handling version control, its security features are equally robust, ensuring that your cod
7 min read
Models in OOAD
While creating software, imagine using blueprints to design a house that's what models do in Object Oriented Analysis and Design (OOAD). Just like blueprints help us understand how a house will be built, models in OOAD help developers visualize and plan out software before they start coding. These m
8 min read
Submodules in Git
In software development, itâs common to manage projects that depend on other projects. Git submodules are a powerful feature that allows you to include and manage external repositories within your main repository. This feature enables you to keep multiple repositories in sync and makes it easier to
3 min read
Mongoose.model() Function
The mongoose.model() function is a core method in the Mongoose library, used for interacting with MongoDB in a Node.js environment. It helps in creating a MongoDB collection associated with a schema, defining the structure of documents that will be stored within it. This article will explain mongoos
4 min read
How to Export a Git Project?
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git relies on the basis of distributed development of software where more than one developer may have access to the source code of a specific ap
3 min read
How to Login to Git?
Git is a popular version control system used by developers to manage code and collaborate on projects. To fully utilize Gitâs features, you need to log in, which involves setting up authentication with a Git hosting service like GitHub, GitLab, or Bitbucket. In this article, weâll guide you through
3 min read
Git Introduction
Git is a powerful and widely used version control system that helps developers track changes in their code, collaborate with others, and manage project history effectively. Whether you are a professional developer or just starting out, understanding Git is important for modern software development.
6 min read
Git Pull Request
Pull requests (PRs) are a fundamental part of collaborative development in Git and are widely used across platforms like GitHub, GitLab, and Bitbucket. A pull request is a mechanism that allows developers to notify others about changes theyâve made to a branch in a Git repository. In this article, w
6 min read
10 MLOps Projects Ideas for beginners
Machine Learning Operations (MLOps) is a practice that aims to streamline the process of deploying machine learning models into production. It combines the principles of DevOps with the specific requirements of machine learning projects, ensuring that models are deployed quickly, reliably, and effic
13 min read