Last updated: September 2026 Β· 11 min read
Git Commands Cheat Sheet: The Complete 2026 Reference
Git's day-to-day commands are simple, add, commit, push, pull. The confusion shows up around the commands that undo or rewrite history, merge versus rebase, reset versus revert, where picking the wrong one can cause real problems on a shared branch.
This page covers the commands you'll use constantly, the two comparisons that trip everyone up, and a searchable lookup near the bottom.
Quick answer: use merge when working on a shared branch, it preserves history safely. Use rebase to clean up your own local commits before sharing them. Use revert on a shared branch to undo a commit safely, and reset only on local, unpushed commits.
Quick Navigation
Essential Git Commands
| Command | What it does |
|---|---|
git init | Creates a new Git repository in the current folder |
git clone [url] | Copies an existing remote repository to your machine |
git status | Shows changed files and what's staged for commit |
git add [file] | Stages a file's changes for the next commit |
git commit -m "message" | Saves staged changes as a new commit |
git push | Uploads local commits to the remote repository |
git pull | Downloads and merges changes from the remote repository |
git log | Shows the commit history |
Branching Commands
| Command | What it does |
|---|---|
git branch | Lists local branches |
git branch [name] | Creates a new branch |
git switch [branch] | Switches to a different branch |
git checkout -b [name] | Creates and switches to a new branch in one step |
git merge [branch] | Merges the named branch into your current branch |
Merge vs Rebase
Both combine changes from one branch into another, but they handle history differently. This matters more once you're collaborating with other people.
git merge
Combines two branches and creates a new merge commit that ties both histories together. Safe on shared branches since it never rewrites commits other people already have.
git rebase
Replays your commits on top of another branch, creating a cleaner, linear history. Rewrites commit history, which is risky if others have already pulled the commits you're rebasing.
Reset vs Revert
Both undo changes, but reset rewrites history while revert adds new history on top. This is the difference that actually matters for anything already pushed and shared.
git reset
Moves your branch pointer backward, effectively erasing commits from history. Safe on local, unpushed work. Risky on a shared branch, since it can wipe out commits others already have.
git revert
Creates a brand new commit that undoes the changes from a previous one, without deleting the original commit. Safe to use on shared branches, since history stays intact for everyone.
Undoing Changes: Full Comparison
| Situation | Command |
|---|---|
| Undo uncommitted changes to a file | git checkout -- [file] |
| Unstage a file, keep the changes | git reset [file] |
| Undo the last local, unpushed commit | git reset --soft HEAD~1 |
| Undo a commit that's already pushed and shared | git revert [commit] |
| Temporarily save changes without committing | git stash |
| Restore stashed changes | git stash pop |
Search Any Git Command
Type a command or keyword to filter the list below.
| Command | What it does |
|---|---|
git init | Creates a new Git repository |
git clone | Copies a remote repository locally |
git status | Shows changed and staged files |
git add | Stages changes for commit |
git commit | Saves staged changes |
git push | Uploads commits to remote |
git pull | Downloads and merges remote changes |
git branch | Lists or creates branches |
git switch | Switches to another branch |
git merge | Combines branch histories with a merge commit |
git rebase | Replays commits on top of another branch |
git reset | Moves the branch pointer, can erase history |
git revert | Undoes a commit by adding a new one |
git stash | Temporarily saves uncommitted changes |
git log | Shows commit history |
git diff | Shows changes between commits or working files |
git fetch | Downloads remote changes without merging them |
git remote -v | Lists connected remote repositories |
No matching command found. Try a different word.
Common Git Workflows, Start to Finish
Individual commands make more sense in the context of the full sequence you'd actually run. Here are three real workflows, command by command.
Starting a feature branch and opening a PR
git checkout main git pull origin main git checkout -b feature/add-search-bar # ... make your changes ... git add . git commit -m "Add search bar to header" git push -u origin feature/add-search-bar # open a pull request from the pushed branch
Undoing a commit you already pushed
git revert HEAD git push origin feature/add-search-bar
git revert creates a new commit that undoes the changes, keeping history intact β the right choice once a commit has been pushed and others might already have it. Save git reset for commits that only exist on your own machine.
Resolving a merge conflict
git checkout main git pull origin main git checkout feature/add-search-bar git merge main # Git marks the conflicting lines with <<<<<<< ======= >>>>>>> # open the file, keep the correct lines, delete the markers git add . git commit -m "Merge main into feature/add-search-bar"
The markers Git inserts show both versions of the conflicting section β your branch's version and the incoming version β separated by =======. Edit the file down to what it should actually say, remove all three marker lines, then stage and commit like normal.
Common Git Mistakes
Using git reset --hard on commits that have already been pushed and pulled by teammates is a fast way to cause real conflicts, since it erases history others are already building on. Revert is the safer tool once anything is shared.
Rebasing a public branch that others have already pulled from is the other classic mistake, it rewrites commit history, which forces everyone else to reconcile their own copy manually. Rebase your own local branches freely, but leave shared branches to merge.
A simple rule: if a commit only exists on your machine, reset and rebase freely. The moment it's pushed and someone else might have it, switch to revert and merge instead.
Want more developer references like this? Check our web tools collection, or our freelance tools page if you're managing client repos. Git config and CI files are usually YAML β see our JSON vs YAML vs XML guide if the syntax trips you up. See the official Git documentation for every command's full option list.
Frequently Asked Questions
Is rebase always more dangerous than merge?+
Not inherently, it's dangerous specifically when used on commits others already have. Rebasing your own local, unpushed commits to clean up history before sharing them is a common and safe practice.
How do I undo my last commit without losing my changes?
git reset --soft HEAD~1 undoes the commit but keeps your changes staged, ready to commit again with a different message or additional edits.
What's the difference between git fetch and git pull?
Fetch downloads the latest remote changes but doesn't merge them into your current branch, letting you review first. Pull does both steps at once, fetch and merge together.
Related reading: Bookmark this page for quick lookups, and check our web tools page for more developer references.

