Git Commands Reference

Explore how essential Git commands reshape your commit history through interactive visual simulations. Understand branches, merges, rebases, and cherry-picks the way Git actually processes them.

Initialize Repository
git init

Creates a new, empty Git repository or reinitializes an existing one. This creates a .git directory with subdirectories and template files.

Visual Example

Check Status
git status

Shows the current state of the working directory and staging area. Displays which files are untracked, which are staged for the next commit, and which have been modified since the last commit. As a read-only command, it observes state but never changes it.

Visual Example

This command does not modify commit history.
On branch main
Untracked files:
(use "git add <file>..." to include in what will be committed)
feature.js

Stage Changes
git add

Adds file contents from the working directory to the staging area, preparing them to be included in the next commit. You can stage all files at once with git add . or stage individual files with git add <filename>.

Visual Example

This command does not modify commit history.
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: feature.js
Note: The file feature.js is now in the staging area, ready to commit.

Create Commit
git commit -m 'message'

Records changes to the repository. This creates a new commit containing the current contents of the index and the given log message describing the changes.

Visual Example

View Commit History
git log

Displays the full commit history of the current branch, showing each commit's hash, author, date, and message. The most recent commit appears at the top. Use git log --oneline for a compact view. This command never modifies the repository.

Visual Example

This command does not modify commit history.
commit c3a8d9b (HEAD -> main)
Author: User <user@example.com>
Date: Today

Third commit
commit b2f7c6e
Author: User <user@example.com>
Date: Yesterday

Second commit
commit a1e5b4c
Author: User <user@example.com>
Date: Two days ago

Initial commit

Show Changes
git diff

Shows the differences between the working directory and the staging area, or between commits. Use it to review exactly what has changed in your files before staging or committing. This is a read-only inspection command.

Visual Example

This command does not modify commit history.
diff --git a/feature.js b/feature.js
index 83db48f..f84236a 100644
--- a/feature.js
+++ b/feature.js
@@ -1,3 +1,4 @@
function init() {
console.log("ready");
+ setupListeners();
}

Manage Branches
git branch feature

Creates a new branch pointer at the current commit. Branches are lightweight pointers to specific commits, allowing you to diverge from the main line of development.

Visual Example

Switch Branches
git checkout feature

Updates files in the working tree to match the version in the specified branch, and updates HEAD to point to that branch.

Visual Example

Merge Branches
git merge feature

Incorporates changes from the named commits into the current branch. This creates a new 'merge commit' that has two parent commits.

Visual Example

Revert Commit
git revert

Creates a new commit that undoes the changes introduced by a previous commit. Unlike reset, revert is non-destructive — the original commit remains in the history and a new undo commit is added on top. This is the safe way to undo changes on shared branches.

Visual Example

Soft Reset
git reset --soft

Moves the HEAD pointer back by one or more commits without discarding your changes. The changes from the undone commits remain in the staging area, ready to be recommitted. Use this to amend commit history while keeping your work intact.

Visual Example

Hard Reset
git reset --hard

Moves the HEAD pointer back by one or more commits and permanently discards all changes from the removed commits. Both the commits and their file changes are gone. Changes discarded permanently. Use with caution — this cannot be undone.

Visual Example

Rebase Commits
git rebase main

Reapplies commits on top of another base tip. This rewrites commit history by creating brand new commits for each commit in the original branch.

Visual Example

Cherry Pick
git cherry-pick C4

Applies the changes introduced by some existing commits on top of the current branch. This creates a new commit with the exact same changes.

Visual Example