38 commands

git init
Initialize Repository
Create a new Git repository in the current directory
git clone
Clone Repository
Copy a remote repository to your machine
git config
Configure Git
Set user name, email, editor, and other Git settings
git config aliases
Create Aliases
Create shortcuts for frequently used commands
git status
Check Status
Show which files are staged, modified, or untracked
git add
Stage Changes
Add files to the staging area before committing
git commit
Commit Changes
Save staged changes with a descriptive message
git rm
Remove Files
Remove files from tracking and working directory
git mv
Move/Rename Files
Rename or move a file and stage the change
.gitignore
Ignore Files
Tell Git which files to never track
git branch
List / Create Branches
List existing branches or create a new one
git switch
Switch Branches
Switch to a different branch (modern, replaces checkout)
git checkout
Checkout Branch or Files
Switch branches or restore files (older, multi-purpose)
git merge
Merge Branches
Combine another branch into your current branch
!git rebase
Rebase Branch
Replay your commits on top of another branch (linear history)
git merge conflicts
Resolve Merge Conflicts
How to handle conflicting changes between branches
git cherry-pick
Cherry-Pick Commits
Copy a specific commit from another branch to current branch
git remote
Manage Remotes
List, add, or remove remote repository connections
git fetch
Fetch from Remote
Download changes from remote WITHOUT merging into your branch
git pull
Pull from Remote
Fetch + merge remote changes into your current branch
!git push
Push to Remote
Upload your local commits to the remote repository
git restore
Restore Files
Discard changes in working directory or unstage files
!git reset
Reset Commits
Move HEAD back and optionally unstage or discard changes
git revert
Revert Commit
Create a NEW commit that undoes a previous commit (safe for shared branches)
!git clean
Clean Untracked Files
Remove untracked files from the working directory
git stash
Stash Changes
Temporarily save uncommitted changes to a stack
git stash pop/apply
Restore Stash
Apply stashed changes back to working directory
!git stash list/drop
Manage Stashes
List, show, or delete stashed changes
git log
View Commit History
Browse the commit log with various formatting options
git diff
Show Changes
Compare changes between commits, branches, or working tree
git show
Show Commit Details
Display details and diff of a specific commit
git blame
Blame (Line-by-Line History)
Show who last modified each line of a file
git reflog
Reference Log
Show every HEAD movement - your safety net for recovery
git tag
Create Tags
Mark specific commits as release points (v1.0, v2.0)
git bisect
Binary Search for Bugs
Find which commit introduced a bug using binary search
git worktree
Multiple Working Trees
Check out multiple branches simultaneously in separate directories
git format-patch / am
Email Patches
Create and apply patches via email or files
git submodule
Submodules
Include other Git repositories inside your repository

Frequently Asked Questions

What is the difference between git merge and git rebase?
git merge creates a merge commit that combines two branches, preserving the branch history. git rebase replays your commits on top of another branch, creating a linear history. Use merge for shared branches, rebase for local feature branches before merging.
How do I undo the last git commit?
Use git reset HEAD~1 to undo the last commit while keeping changes in your working directory. Use --soft to keep changes staged, --mixed (default) to unstage them, or --hard to discard them entirely. For already-pushed commits, use git revert HEAD instead.
What is the difference between git fetch and git pull?
git fetch downloads changes from the remote without modifying your local branches. It only updates remote-tracking branches (like origin/main). git pull does git fetch followed by git merge, actually integrating remote changes into your current branch. fetch is always safe; pull may cause merge conflicts.
How do I resolve a merge conflict?
Open the conflicted file, find the conflict markers (<<<<<<< HEAD, =======, >>>>>>> branch), edit the file to keep the correct code, remove the markers, then run git add on the file and git commit. Use git status to see which files have conflicts.
What does git stash do?
git stash temporarily saves your uncommitted changes (both staged and unstaged) to a stack, giving you a clean working directory. Use git stash pop to restore the changes later. This is useful when you need to switch branches but are not ready to commit.
How do I recover a deleted branch or lost commit?
Use git reflog to see the history of all HEAD movements. Find the commit hash of the lost work, then use git checkout -b recovered-branch <hash> to create a new branch at that point. Reflog entries are kept for about 90 days by default.

About This Git Reference

This interactive Git commands reference covers 38 essential commands organized into 10 categories. Each command includes clean syntax, practical examples you can copy-paste, and visual ASCII diagrams that show exactly what Git does behind the scenes.

Whether you're a beginner learning Git basics or an experienced developer looking up the exact flag for git rebase -i, this reference is designed to be bookmarked and revisited. Search by command name, flag, or description to find exactly what you need.