What Data Structure Is Used by Git?


Heather Bennett

Git is a widely used version control system that helps developers track changes to their codebase. Behind the scenes, Git uses a data structure called a Directed Acyclic Graph (DAG) to organize and store the history of changes.

Understanding the DAG

The DAG in Git consists of nodes, where each node represents a snapshot of the code at a particular point in time. These snapshots are commonly referred to as commits. Each commit contains information about the changes made, including the author, timestamp, and a unique identifier called a SHA-1 hash.

One of the key features of Git is its ability to create branches. A branch is simply a pointer that points to a specific commit within the DAG.

When you create a new branch, Git creates a new pointer that points to the same commit as the current branch. This allows developers to work on different features or bug fixes simultaneously without interfering with each other’s work.

The Commit Object

At the heart of Git’s data structure is the commit object. Each commit object contains several important pieces of information:

  • Author: The person who made the changes.
  • Committer: The person who committed those changes into Git.
  • Message: A brief description of what changes were made.
  • Parent(s): The commit(s) that come before this one.

The parent field is what enables Git to construct its DAG structure. By keeping track of which commits come before each other, Git can easily traverse through the history and understand how each snapshot relates to another.

Merging and Branching

In Git, merging is the process of combining two or more branches into a single branch. When you merge two branches, Git creates a new commit that has both branches as its parents. This results in a new snapshot that incorporates the changes from both branches.

Branching, on the other hand, is the process of creating a new branch that shares the commit history of an existing branch. The new branch starts at the same commit as the original branch and allows developers to work on new features or experiments independently.


In summary, Git uses a Directed Acyclic Graph (DAG) as its underlying data structure to manage and store the history of changes. Commits are represented as nodes in this graph, with each commit containing information about the changes made and pointers to its parent commits. By leveraging this powerful data structure, Git enables developers to work efficiently with branching, merging, and tracking code changes.

Discord Server - Web Server - Private Server - DNS Server - Object-Oriented Programming - Scripting - Data Types - Data Structures

Privacy Policy