Essential git commands with flags and short descriptions.
Searchable reference of the most-used git commands grouped by area — staging, committing, branching, merging, rebasing, remotes and undo — each with common flags and a clear purpose. It runs free in your browser on Gera Tools, with nothing uploaded.
Last updated · Source: Gera Tools
What is the difference between git merge and git rebase?
Merge joins two branches with a merge commit, preserving the exact history of both. Rebase replays your commits on top of another branch, producing a linear history but rewriting commit hashes. Use merge to integrate shared branches and rebase to tidy a local branch before sharing — never rebase commits others have already pulled.
Get one useful tool a week
Like this tool? Enter your email and we'll send you one genuinely
useful Gera tool a week — plus a link to come back to this one.
No spam, one-click unsubscribe any time.
The git commands you actually use, organised
Git has hundreds of commands, but day-to-day work runs on a couple dozen. This
reference groups the essentials by area — setup, staging, committing, branching,
integrating, remotes and undo — with the common flags and a one-line description
for each, so you can find the right command and its key options fast.
How git’s three-location model works
Git tracks three places: the working tree (your files on disk), the index (also called the staging area — what the next commit will contain), and the commit history (the chain of snapshots). Most commands move changes between these:
git add -p # stage selected hunks into the indexgit commit -m "message" # record the index as a commitgit switch -c feature # create and move onto a new branchgit rebase main # replay feature commits onto the latest maingit push -u origin feature --force-with-lease
Remote commands (fetch, pull, push) sync that history with a server, and undo commands (reset, revert, restore, reflog) walk it back when something goes wrong.
Command areas at a glance
Staging and committing
Command
What it does
git add -p
Interactively stage hunks — the best way to make clean commits
git commit -m "msg"
Record staged changes as a new commit
git commit --amend
Rewrite the most recent commit (local only — never on shared branches)
git stash push -m "desc"
Save uncommitted work to a temporary stack entry
git stash pop
Restore the most recent stash entry
Branching and navigating
Command
What it does
git switch -c feature
Create and move to a new branch
git switch main
Move to an existing branch
git branch -d feature
Delete a merged branch locally
git log --oneline --graph
Visualise the commit graph compactly
Integrating changes
Command
What it does
git merge feature
Join feature into the current branch with a merge commit
git rebase main
Replay current-branch commits on top of main (rewrites hashes)
git cherry-pick <sha>
Apply a single commit from another branch
Remotes and sharing
Command
What it does
git fetch origin
Download updates without merging
git pull --rebase
Fetch and replay local commits on top of the remote
git push -u origin feature
Push and set upstream tracking
git push --force-with-lease
Force-push safely — aborts if remote has changed
Undo and recovery
Command
What it does
git revert <sha>
Create a new commit that reverses a prior one — safe on shared branches
git reset --soft HEAD~1
Undo last commit but keep changes staged
git restore <file>
Discard unstaged changes to a file
git reflog
List every HEAD position — your recovery net for “lost” commits
Tips and notes
Stage precisely with git add -p so each commit is a coherent, reviewable change.
Prefer git revert on shared branches; reserve git reset --hard for local cleanup you are sure about.
Use git push --force-with-lease, never bare --force, after rebasing.
Keep git reflog in mind — it is your safety net for recovering commits that a reset or rebase appeared to delete. Reflog entries persist for weeks by default.
git switch and git restore are the modern, focused replacements for the overloaded git checkout command — prefer them in new scripts and workflows.