Love Git Branches But Hate Reading Them?
If you’re using git branching, it can be difficult sometimes to orient yourself within your git repository (repo).
Knowing where you are, where you want to go, and how to get there is next to impossible if you don’t know how to read your commit history (branches)
So I’m going to show you how to read your commit history in this post.
Commits
Here’s your first insight: Commits always point BACK to their parent commit(s), never forward to their child commit(s):
If you make some changes and commit again, the next commit stores a pointer to the commit that came immediately before it.
3.1 Git Branching – Branches in a Nutshell, Figure 10.
This subtle distinction may not seem like a big deal now, but soon this will make all the difference.
Reading Commits
Here is the output of the branch master from my local repo:
git log --oneline --graph --decorate

Given that commits always point back, we can trace our branch from Branch Pointer master (78f107a) all the way back down to our initial commit (7bc8a7a):

The totality of the entire trail from the most recent commit master (78f107a) all the way back down to our initial commit (7bc8a7a) is one branch.
Reading Multiple Branches
Here is where knowing commits point back, not forward, is REALLY going to help us out
First we expose ALL branches from my git repo:
git log --oneline --graph --decorate --all

In this output we now can see all branches laid out at once.
Reading the dev Branch
Here are a couple of things to remember when reading the commit history from command ‘git log’:
- The previous commit(s) is denoted by following back to the previous asterisk(s), not necessarily the commit beneath it.
- The vertical and diagonal bars actually do a great job of guiding us to the previous commit(s).

7bc8a7a <= a6b939a <= 8e005a4 <= 0461fc6 <= 5e3384e (dev)
We can confirm this by checking out the dev branch and listing the commit history

Reading the test Branch
Just repeat the same process for branch test and you will get the following:

Confirming the test branch:

7bc8a7a <= a6b939a <= 8e005a4 <= e5a2bcc <= 3d6f3bb (test)
Summary
Now that you know how to read your commit history (branches) you should be able to orient yourself and navigate within your git repo.
Hopefully this will empower you to leverage git branches more when you need to experiment with different version and features of your code.
Branches will allow you to test your experimental code without losing the production code.