Git Commands Cheat Sheet: The Commands You Actually Use
Git has hundreds of commands, but day-to-day work runs on a couple of dozen. This is that practical set — grouped by task, from staging and committing to branching, remotes, and undoing mistakes. Angle brackets <like this> mark a value you fill in.
Updated 2026-07-06
Setup
| Command | What it does |
|---|---|
| git init | Start a new repository in the current folder |
| git clone <url> | Copy a remote repository to your machine |
| git config --global user.name "Name" | Set your commit author name |
| git config --global user.email "you@x.com" | Set your commit author email |
Staging & committing
| Command | What it does |
|---|---|
| git status | Show changed, staged, and untracked files |
| git add <file> | Stage a file for the next commit |
| git add . | Stage all changes in the current folder |
| git reset <file> | Unstage a file (keep the changes) |
| git commit -m "message" | Commit staged changes with a message |
| git commit -am "message" | Stage tracked files and commit in one step |
| git commit --amend | Edit the most recent commit |
Branching
| Command | What it does |
|---|---|
| git branch | List local branches |
| git branch <name> | Create a new branch |
| git checkout <name> | Switch to a branch |
| git switch <name> | Switch to a branch (newer syntax) |
| git checkout -b <name> | Create and switch to a new branch |
| git branch -d <name> | Delete a merged branch |
| git branch -D <name> | Force-delete a branch |
Merging & rebasing
| Command | What it does |
|---|---|
| git merge <branch> | Merge a branch into the current one |
| git rebase <branch> | Replay your commits on top of another branch |
| git rebase -i <ref> | Interactively edit, squash, or reorder commits |
| git cherry-pick <hash> | Apply a single commit onto the current branch |
Remotes
| Command | What it does |
|---|---|
| git remote -v | List configured remotes |
| git remote add origin <url> | Connect a local repo to a remote |
| git fetch | Download remote changes without merging |
| git pull | Fetch and merge remote changes |
| git push | Upload your commits to the remote |
| git push -u origin <branch> | Push and set the upstream branch |
Undoing things
| Command | What it does |
|---|---|
| git restore <file> | Discard uncommitted changes to a file |
| git reset --soft HEAD~1 | Undo the last commit, keep changes staged |
| git reset --hard HEAD~1 | Undo the last commit and discard changes |
| git revert <hash> | Create a new commit that undoes a commit |
| git stash | Shelve changes to work on something else |
| git stash pop | Reapply the most recently stashed changes |
Inspecting history
| Command | What it does |
|---|---|
| git log | Show the commit history |
| git log --oneline | Compact one-line-per-commit history |
| git diff | Show unstaged changes |
| git diff --staged | Show staged changes |
| git show <hash> | Show the details of a specific commit |
| git blame <file> | Show who last changed each line |