Visualizing Git: Merge, Rebase, Reset, Revert, Fetch, Pull & Reflog Explained
This article uses animated diagrams to clearly illustrate how common Git commands—including merge (fast‑forward and no‑ff), rebase, reset (soft and hard), revert, cherry‑pick, fetch, pull, and reflog—operate on branches, commits, and history, helping developers understand and avoid common pitfalls.
Introduction
Git is a powerful version‑control tool, but many developers struggle to visualize what happens when they run commands such as git merge, git rebase, git reset, git revert, git fetch, git pull or git reflog. This article, originally created by 21‑year‑old software consultant Lydia Hallie, presents animated GIFs that show the internal mechanics of these commands, making the concepts memorable.
Merge
When you want to integrate changes from one branch into another, you use git merge. Git supports two merge strategies:
Fast‑forward (‑‑ff) : If the current branch has no extra commits beyond the target branch, Git simply moves the branch pointer forward, creating no new commit.
No‑fast‑forward (‑‑no‑ff) : If the current branch has diverging commits, Git creates a new merge commit whose parents are the two branches being merged.
Animated diagrams demonstrate both cases, showing how the commit graph changes after each merge.
Merge Conflicts
If the same line of a file is edited differently on the two branches, Git cannot decide automatically and marks a conflict. The article shows a conflict on README.md where one branch wants “Hello!” and the other wants “Hey!”. It explains how to resolve the conflict manually, stage the resolved file, and commit.
Rebase
git rebaserewrites history by moving the current branch’s commits onto another base branch, producing new commit hashes. This results in a linear history without merge commits, which can avoid future conflicts. The article also covers interactive rebase , allowing developers to reword, edit, squash, fixup, exec, or drop individual commits before applying them.
Reset
When a commit should be discarded, git reset is used. Two modes are highlighted:
Soft reset : Moves HEAD to a previous commit but leaves the working directory and index unchanged, preserving the changes for a new commit.
Hard reset : Moves HEAD and resets both the index and working directory to the specified commit, discarding all subsequent changes.
Examples show resetting away unwanted commits while optionally keeping file modifications.
Revert
git revertcreates a new commit that undoes the changes introduced by a specific earlier commit, without rewriting history. The article demonstrates reverting a commit that added index.js, preserving the linear commit graph.
Cherry‑pick
git cherry-pickcopies a single commit from another branch onto the current branch, useful when only a specific change is needed. An example moves a commit that modifies index.js from dev to master without merging the whole branch.
Fetching and Pulling
git fetchdownloads new objects and refs from a remote repository without altering local branches. git pull combines fetch followed by a merge, automatically integrating the fetched changes into the current branch. Animated diagrams illustrate the data flow and resulting branch updates.
Reflog
git reflogrecords every move of HEAD, providing a safety net for recovering from mistakes. The article shows how to view the reflog, identify a previous state (e.g., HEAD@{1}), and use git reset to restore that state.
Overall, the visual approach helps developers grasp the effects of each command on branch topology, commit history, and working files, reducing confusion and preventing common errors.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
