Fundamentals 12 min read

10 Essential Git Commands Visualized: Master Git Quickly

This article walks through ten core Git commands—including merge, rebase, reset, revert, cherry‑pick, fetch, pull, and reflog—using animated GIFs and concrete examples to illustrate how each command manipulates branches, history, and repository state, helping readers visualize and retain the concepts.

Linux Tech Enthusiast
Linux Tech Enthusiast
Linux Tech Enthusiast
10 Essential Git Commands Visualized: Master Git Quickly

Merge

Git can combine changes from one branch into another using git merge. Two merge types exist: fast‑forward (‑ff) merges when the current branch has no extra commits, which simply moves the branch pointer, and no‑fast‑forward (‑no‑ff) merges that create a new merging commit when the current branch has diverging work.

When a conflict occurs—e.g., both branches edit the same line in README.md —Git prompts the user to choose which version to keep, after which the conflict must be resolved manually before committing.

Rebase

git rebase

copies the current branch’s commits onto another branch, producing new commit hashes. This creates a linear history without merge commits, avoiding most merge conflicts. However, it rewrites history, which can be problematic for shared branches.

Interactive Rebase

Before rebasing, git rebase -i lets you edit, reorder, squash, fixup, or drop commits. The six possible actions are reword, edit, squash, fixup, exec, and drop, giving fine‑grained control over the resulting history.

reword – change commit message

edit – modify the commit

squash – combine with previous commit

fixup – combine without keeping message

exec – run a command for each commit

drop – remove the commit

Reset

git reset

moves HEAD to a specified commit. A soft reset ( --soft) moves the pointer but leaves index and working‑tree changes intact, useful for un‑committing while keeping modifications. A hard reset ( --hard) discards all changes, resetting the working tree and index to the target commit.

Example: resetting from commits 9e78i and 035cc while preserving newly added files style.css and index.js demonstrates a soft reset.

Revert

git revert

creates a new commit that undoes the changes introduced by a specified earlier commit, preserving history. For instance, reverting commit ec5be removes the added index.js file without altering the commit graph.

Cherry‑pick

git cherry-pick

copies a single commit from another branch onto the current branch, creating a new commit with the same changes. This is useful when only a specific feature or fix is needed without merging the whole branch.

Fetch and Pull

git fetch

downloads objects and refs from a remote repository without altering local branches. git pull combines fetch and merge, automatically merging the fetched changes into the current branch.

Reflog

git reflog

records every movement of HEAD, including merges, resets, and reverts, providing a safety net for recovering lost work. By inspecting the reflog, one can reset HEAD to a previous state (e.g., HEAD@{1}) to undo mistakes.

GitfetchmergerebaseVersion Controlpullresetrevert
Linux Tech Enthusiast
Written by

Linux Tech Enthusiast

Focused on sharing practical Linux technology content, covering Linux fundamentals, applications, tools, as well as databases, operating systems, network security, and other technical knowledge.

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.