Cheatsheet Hub

Interactive cheatsheets with examples. Ask AI if you don't understand something.

Basics

8
Init repository
git init

Create a new local repository

Clone repository
git clone <url>

Clone a remote repository

Check status
git status

Show working tree status

Stage files
git add <file>

Add files to staging area

Stage all
git add .

Stage all changes

Commit
git commit -m "message"

Commit staged changes

View log
git log --oneline

Show commit history (compact)

Show diff
git diff

Show unstaged changes

Branches

9
List branches
git branch

List all local branches

Create branch
git branch <name>

Create a new branch

Switch branch
git checkout <name>

Switch to a branch

Create & switch
git checkout -b <name>

Create and switch to a new branch

Merge branch
git merge <branch>

Merge branch into current

Delete branch
git branch -d <name>

Delete a branch (safe)

Rebase
git rebase <branch>

Rebase current branch onto another

Switch branch
git switch <name>

Modern way to switch branches (Git 2.23+)

Create & switch
git switch -c <name>

Create and switch to a new branch (modern)

Remote

5
Add remote
git remote add origin <url>

Add a remote repository

Push
git push -u origin <branch>

Push branch and set upstream

Pull
git pull

Fetch and merge remote changes

Fetch
git fetch

Download remote changes without merging

List remotes
git remote -v

Show remote URLs

Undo & Fix

8
Unstage file
git reset HEAD <file>

Remove file from staging

Discard changes
git checkout -- <file>

Discard working directory changes

Amend commit
git commit --amend

Modify the last commit

Revert commit
git revert <hash>

Create a new commit that undoes changes

Stash changes
git stash

Temporarily save uncommitted changes

Apply stash
git stash pop

Restore stashed changes

Restore file
git restore <file>

Discard working directory changes (modern, replaces checkout --)

Unstage (modern)
git restore --staged <file>

Remove file from staging area (modern, replaces reset HEAD)