Skip main navigation

An introduction to the Git graph

In this short article, Dr Fardeen Mackenzie introduces a key concept for the course: the Git commit graph.

One of the most important benefits Git provides is the ability to describe and visualise the history of changes in a project.

Understanding how to interpret this information is key both to understanding the current state of the project and also in grasping how Git and its various commands work.

Imagine you have joined a new team and you have been supplied with a current copy of the codebase. You will need to orientate yourself with the state of the project. This is part of the “onboarding” process that is common for software developers joining a new team. One of the ways which Git can facilitate onboarding is by helping you understand the project and its history.

A key tool to achieve this is the Git graph view.

Examine the following simple graph and investigate what it tells us about this project.

Diagram of a Git graph showing a simple vertical graph with three branches

If this is your first time seeing a Git graph it may seem a little overwhelming at first but don’t worry, the entire graph is made of just a few key elements.

On the left-hand side of the graph, you can see that it is constructed from a series of connected nodes. Each node is referred to as a “commit”. A commit can be thought of as a snapshot of the entire project at a point in time. It is possible to explore the graph, selecting any commit and viewing the state of the project at that point in time.

Next to each node, you can see three important pieces of information. The first is a string of characters that is used to uniquely identify that particular commit. You will learn more about these identifiers later in the course. After the identifier comes the commit message. When you make a commit (that is, save a snapshot of the project) you can enter a message that describes the changes you have made. It is common for the first commit in a project to be made before any code is written. Finally, you can see who authored the changes and made the commit.

A commit line with all the elements annotated

This particular graph is intended to be read vertically, bottom-to-top. The commit at the bottom of the graph is the “earliest” commit in the project’s history. The first commit is connected by a line to another commit with the message “Add log-in screen”. This suggests the changes made between the first commit and the second were intended to add a login process. These commits are connected because the “Add log-in screen” commit represents changes which are based directly on the “Initial commit” version of the project.

Whether this was a sensible way to start the development of this project is debatable, but at least you know how the codebase began. You may even be able to infer something about the company culture or level of experience within the team based on the development history.

It should be noted that other ways of drawing Git graphs are sometimes used, such as a horizontal layout, illustrated below.

Diagram of a Git graph showing a simple horizontal graph with three branches

We usually read horizontal Git graphs from left-to-right, so the earliest commit here is the one on the left.

© The University of Manchester
This article is from the free online

Collaborative Coding with Git

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now