Tags: git, github, cli, gui, version-control Last updated: 2026-06-26

GitHub Cheatsheet

Quick Reference

CommandDescription
git clone <url>Download a repo
git pullFetch + merge remote changes
git add -A && git commit -m "msg"Stage all + commit
git pushUpload commits to remote
git statusSee what changed
git log --onelineCompact commit history
git branchList local branches
git checkout -b <name>Create + switch branch
git stashTemporarily shelve changes
gh pr createOpen a pull request (CLI)

Setup & Authentication

First-Time Git Config

$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
$ git config --global core.autocrlf true
$ git config --global init.defaultBranch main

GitHub CLI (gh) Auth

$ gh auth login
# Follow prompts: GitHub.com → HTTPS → Login with browser
$ gh auth status

SSH Key (Skip Password Prompts)

$ ssh-keygen -t ed25519 -C "[email protected]"
# Upload ~/.ssh/id_ed25519.pub at:
#   github.com → Settings → SSH and GPG keys
$ ssh -T [email protected]

Repositories

Create & Clone

$ gh repo create my-project --public --clone
$ gh repo create my-project --private --clone
$ git clone https://github.com/user/repo.git
$ git clone [email protected]:user/repo.git

Remote Management

$ git remote -v
$ git remote add upstream <url>
$ git remote set-url origin <new-url>
$ git remote remove <name>

Fork Workflow

$ gh repo fork owner/repo --clone
$ git remote add upstream https://github.com/owner/repo.git
$ git fetch upstream
$ git merge upstream/main

Daily Workflow

Staging & Committing

$ git status -s
$ git diff                  # Unstaged changes
$ git diff --staged         # Staged changes
$ git add <file>
$ git add -p                # Stage hunks interactively
$ git commit -m "message"
$ git commit --amend        # Edit last commit message

Branching

$ git branch                # List local branches
$ git branch -a             # List all (remote too)
$ git checkout <branch>
$ git checkout -b <new-branch>
$ git switch <branch>       # Git ≥2.23 alternative
$ git switch -c <new-branch>
$ git branch -d <branch>    # Delete local
$ git push origin -d <branch>   # Delete remote
$ git branch -m <old> <new> # Rename branch

Syncing

$ git pull origin main
$ git pull --rebase origin main
$ git push origin <branch>
$ git push -u origin <branch>   # Set upstream + push
$ git fetch --prune              # Clean stale remote refs

Stashing

$ git stash                 # Shelve changes
$ git stash list
$ git stash pop             # Restore + drop stash
$ git stash apply           # Restore, keep stash
$ git stash drop            # Delete a stash
$ git stash clear           # Delete all stashes

Undoing & Recovery

ActionCommand
Unstage a filegit restore --staged <file>
Discard unstaged changesgit restore <file>
Revert last commit (safe)git revert HEAD
Reset last commit, keep filesgit reset --soft HEAD~1
Reset last commit, wipe filesgit reset --hard HEAD~1
Recover deleted branchgit refloggit checkout -b <name> <hash>

History & Logs

$ git log --oneline --graph --all
$ git log --author="Name"
$ git log --since="2026-06-01"
$ git log -S"keyword"               # Search commit diffs
$ git blame <file>                  # Line-by-line authorship
$ git show <commit-hash>
$ git diff <branch1>..<branch2>

Pull Requests (GitHub CLI)

$ gh pr create --title "Fix login" --body "Closes #42"
$ gh pr list
$ gh pr view
$ gh pr checkout <number>
$ gh pr merge <number> --squash
$ gh pr merge <number> --rebase
$ gh pr close <number>

Reviewing

$ gh pr diff <number>
$ gh pr review <number> --approve
$ gh pr review <number> --request-changes -b "Needs tests"
$ gh pr review <number> --comment -b "LGTM"

Issues (GitHub CLI)

$ gh issue create --title "Bug: ..." --body "..."
$ gh issue list
$ gh issue view <number>
$ gh issue close <number>
$ gh issue reopen <number>

Tags & Releases

$ git tag v1.0.0
$ git tag -a v1.0.0 -m "Release v1.0.0"
$ git push origin v1.0.0
$ git push origin --tags
$ git tag -d v1.0.0
$ git push origin --delete v1.0.0
$ gh release create v1.0.0 --title "v1.0.0" --notes "Notes"
$ gh release list
$ gh release download v1.0.0

GUIs at a Glance

GitHub Desktop

VS Code Built-in

GitHub.com Web

Merge Conflict Resolution

# Conflict markers appear in files:
# <<<<<<< HEAD      (your changes)
# =======           (separator)
# >>>>>>> branch    (incoming changes)

$ git merge <branch>
# Resolve conflicts in files manually, then:
$ git add <resolved-files>
$ git commit
$ git merge --abort     # Cancel the merge

.gitignore Quick Reference

# OS files
.DS_Store
Thumbs.db

# Dependencies
node_modules/
vendor/

# Build output
dist/
build/
*.exe
*.dll

# Secrets
.env
*.pem

# IDE
.vscode/settings.json
.idea/

Tips