Visual Guide to Common Git Commands and Their Detailed Explanation
This article provides a comprehensive visual guide to the most frequently used Git commands, explaining their purpose, usage, and effects on the working directory, index, and repository, while illustrating concepts such as commits, branches, merges, rebases, and detached HEAD with clear diagrams.
This article presents a visual guide to the most commonly used Git commands, helping readers understand Git's workflow and internal mechanisms.
Basic Usage : The four fundamental commands— git add files , git commit , git reset – files , and git checkout – files —move files between the working directory, the index (staging area), and the repository. Interactive modes ( git add -p , git reset -p , git checkout -p ) are also mentioned.
Conventions : Diagrams use green five‑character IDs for commits, orange for branches, and a HEAD label for the current branch. The latest commit is highlighted, and branch relationships are shown.
Command Details :
Diff : Various ways to view changes between commits are illustrated.
Commit : A commit creates a new snapshot from the index, updates the branch pointer, and can be amended with git commit --amend .
Checkout : Copies files from a commit or the index to the working directory and can switch branches; a detached HEAD occurs when checking out a specific commit, tag, or SHA‑1.
Reset : Moves the current branch pointer and optionally updates the working directory and index ( --hard , --soft ).
Merge : Combines two branches, performing a fast‑forward when possible or a three‑way merge otherwise.
Cherry‑Pick : Copies a single commit onto the current branch.
Rebase : Replays a series of commits onto another base, creating a linear history; interactive mode ( git rebase -i ) allows editing, reordering, or dropping commits.
All commands are demonstrated on a topic branch, not directly on master , to show how history is rewritten safely.
Technical Notes : Git stores file contents as blobs in .git/objects identified by SHA‑1 hashes; the index ( .git/index ) tracks which blobs are staged. Detached HEAD commits are reachable via the reflog but may be garbage‑collected if not referenced.
References : Links to the original visual guide and related documentation (merge, rebase, detached HEAD, interactive rebase) are provided.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
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.