2 min read · updated 18 Nov 2026
Git Basics Cheat Sheet
The most common Git commands for tracking changes, branching, and working with remotes
Setup
| Command | What it does |
|---|---|
git config --global user.name "Name" | Sets your name for all commits |
git config --global user.email "you@example.com" | Sets your email for all commits |
git config --list | Shows your current configuration |
Starting a Repository
| Command | What it does |
|---|---|
git init | Creates a new repo in the current folder |
git clone <url> | Copies a remote repo to your machine |
Checking State
| Command | What it does |
|---|---|
git status | Shows changed, staged, and untracked files |
git diff | Shows unstaged changes line by line |
git diff --staged | Shows staged changes ready to commit |
git log | Shows the commit history |
git log --oneline | Shows history one line per commit |
Staging and Committing
| Command | What it does |
|---|---|
git add <file> | Stages a specific file |
git add . | Stages all changes in the current folder |
git commit -m "message" | Commits staged changes with a message |
git commit --amend | Edits the last commit (before pushing) |
Undoing Changes
| Command | What it does |
|---|---|
git restore <file> | Discards unstaged changes in a file |
git restore --staged <file> | Unstages a file without losing changes |
git revert <commit> | Creates a new commit that undoes a previous one |
git reset --soft HEAD~1 | Undoes last commit, keeps changes staged |
Branches
| Command | What it does |
|---|---|
git branch | Lists all local branches |
git branch <name> | Creates a new branch |
git switch <name> | Switches to a branch |
git switch -c <name> | Creates and switches to a new branch |
git merge <branch> | Merges a branch into the current one |
git branch -d <name> | Deletes a branch (safe, only if merged) |
Working with Remotes
| Command | What it does |
|---|---|
git remote -v | Lists remote connections |
git remote add origin <url> | Adds a remote called origin |
git push origin <branch> | Pushes branch to remote |
git push -u origin <branch> | Pushes and sets upstream tracking |
git pull | Fetches and merges remote changes |
git fetch | Downloads remote changes without merging |
Stashing
| Command | What it does |
|---|---|
git stash | Saves uncommitted changes temporarily |
git stash pop | Restores the most recent stash |
git stash list | Lists all stashes |
Quick Workflow Reference
# Start a feature
git switch -c my-feature
# Make changes, then:
git add .
git commit -m "Add my feature"
# Merge back to main
git switch main
git merge my-feature
git push origin mainMore cheat sheets
Not sure your computer can run a model? Use the will-it-run checker.

