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 Repositorygit 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 Statusgit 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
Stage Changesgit 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
feature.js is now in the staging area, ready to commit.Create Commitgit 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 Historygit 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
Author: User <user@example.com>
Date: Today
Third commit
Author: User <user@example.com>
Date: Yesterday
Second commit
Author: User <user@example.com>
Date: Two days ago
Initial commit
Show Changesgit 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
index 83db48f..f84236a 100644
--- a/feature.js
+++ b/feature.js
@@ -1,3 +1,4 @@
function init() {
console.log("ready");
+ setupListeners();
}
Manage Branchesgit 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 Branchesgit 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 Branchesgit 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 Commitgit 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 Resetgit 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 Resetgit 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 Commitsgit 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 Pickgit 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.