Fundamentals 9 min read

Understanding Git History and Branch Merges: A Practical Walkthrough

This article explains how Git records history using a graph of commits, demonstrates creating feature and hotfix branches, shows fast‑forward and merge operations with command‑line examples, and clarifies how branch pointers move during typical enterprise development workflows.

DevOps
DevOps
DevOps
Understanding Git History and Branch Merges: A Practical Walkthrough

g4e (Git for Enterprise Developer) is used as a tag for this series of articles. The article begins by introducing a common development scenario where a developer works on a new feature in a feature1 branch, then must pause to create a hotfix branch for an urgent production issue.

It shows the initial repository state after four commits on master and visualizes the commit graph using git log --oneline --graph. The output demonstrates a linear history where master points to the latest commit (C4).

Next, the article creates feature1 and makes two additional commits. Although a new branch exists, the log still appears linear because Git only moves the branch pointer; master still points to C4 while feature1 points to C6.

When a critical issue arises, the developer switches back to master and creates a hotfix branch:

git checkout master
git checkout -b hotfix

Two more commits are added on hotfix, moving its pointer to C8. The article explains why the log still looks like a single line: each branch’s history is a single‑direction chain.

To integrate the fix, the developer merges hotfix into master:

git checkout master
git merge hotfix

Because hotfix was created from master, Git performs a fast‑forward, simply moving master to point to C8. The article notes the difference between the local master and the remote origin/master pointers.

After the hotfix, development on feature1 continues. Once feature work is complete (commit C9), the branch is merged back into master:

git checkout master
git merge feature1

This merge creates a new commit (e.g., b5bcb0b) with the message “Merge branch ‘feature1’”. The article warns that automatic merges may involve auto‑merged files, which can require careful review.

The final commit graph shows how Git’s pointer‑based model enables flexible branching and merging, and the article concludes that understanding these mechanisms is essential for enterprise‑level development.

All example code is available at https://github.com/lean-soft/git-history-demo , and references include the official Git book.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Gitmergecommand-lineVersion Controlbranching
DevOps
Written by

DevOps

Share premium content and events on trends, applications, and practices in development efficiency, AI and related technologies. The IDCF International DevOps Coach Federation trains end‑to‑end development‑efficiency talent, linking high‑performance organizations and individuals to achieve excellence.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.