Git Cheat Sheet: Essential Commands (Printable)

Keep this Git command cheat sheet nearby for everyday tasks: checking changes, creating commits, working with branches and remotes, and recovering safely. Commands are grouped by what you want to do, with short notes on when to use them.

Print this page: open your browser's print dialog with Ctrl + P on Windows or Linux, or ⌘ + P on Mac. Choose your preferred paper size and scale in the print dialog.

Start here: inspect your repository

CommandWhat it does
git statusShows the current branch and working tree changes.
git status --shortShows a compact summary of changed files.
git log --oneline --graph --decorateShows a compact commit history and branch references.
git diffShows unstaged changes in tracked files.
git diff --stagedShows changes selected for the next commit.

Stage and commit changes

git add <file>                 Stage one file
git add -p                    Choose changes interactively
git add .                     Stage changes under the current directory
git commit -m "Describe change"  Create a commit
git commit --amend            Replace the latest local commit

Review git diff --staged before committing. Amending changes the commit ID; avoid amending commits already shared with others unless the team has agreed to rewrite that history.

Work with branches

git branch                    List local branches
git switch -c <name>          Create and switch to a branch
git switch <name>              Switch branches
git merge <branch>             Merge a branch into the current branch
git branch -d <name>           Delete a merged local branch

Save or otherwise protect uncommitted work before switching branches. Git may prevent a switch if it would overwrite changes.

Connect to a remote

git remote -v                  List remote names and URLs
git fetch                     Download updates; do not integrate yet
git pull                      Fetch and integrate into the current branch
git push                      Send commits to the configured upstream
git push -u origin <branch>   Push and set the upstream for this branch

Fetch before integrating when you want to inspect incoming changes. A push may be rejected if the remote has commits your local branch is missing; integrate them using your project's workflow instead of force-pushing blindly.

Undo or save work carefully

GoalCommandNote
Unstage a filegit restore --staged <file>Keeps edits in the working tree.
Discard unstaged editsgit restore <file>Replaces edits with the indexed version.
Undo a local commit, keep staged changesgit reset --soft HEAD~1Moves the current branch back one commit.
Reverse a shared commitgit revert <commit>Creates a new commit that reverses it.
Save work temporarilygit stash push -u -m "message"Includes untracked files; ignored files are excluded.

Caution: git reset --hard and git clean can discard work. Check git status and confirm what will be removed before using destructive commands.

Configuration and ignore rules

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --list              Show configuration
git check-ignore -v <file>     Find the ignore rule matching a file

Set your author name and email with the identity you want recorded in commits. A .gitignore rule affects untracked files; it does not automatically untrack files already committed.

A safe everyday Git workflow

  1. Run git status to confirm your branch and changes.
  2. Create or switch to the branch for your task.
  3. Make a focused change and review it with git diff.
  4. Stage the intended files and inspect git diff --staged.
  5. Commit with a message that explains the purpose of the change.
  6. Fetch or pull updates as needed, then push your branch.

Learn Git Faster by Practicing

Reading is just the first step. Real learning happens when you practice.

Start Learning Git →