← Cheatsheets
Tags: git, github, cli, gui, version-control
Last updated: 2026-06-26
GitHub Cheatsheet
Quick Reference
| Command | Description |
git clone <url> | Download a repo |
git pull | Fetch + merge remote changes |
git add -A && git commit -m "msg" | Stage all + commit |
git push | Upload commits to remote |
git status | See what changed |
git log --oneline | Compact commit history |
git branch | List local branches |
git checkout -b <name> | Create + switch branch |
git stash | Temporarily shelve changes |
gh pr create | Open 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
| Action | Command |
| Unstage a file | git restore --staged <file> |
| Discard unstaged changes | git restore <file> |
| Revert last commit (safe) | git revert HEAD |
| Reset last commit, keep files | git reset --soft HEAD~1 |
| Reset last commit, wipe files | git reset --hard HEAD~1 |
| Recover deleted branch | git reflog → git 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
- Stage: Check files → write summary → click Commit
- Branch: Current Branch dropdown → New Branch
- Push/Pull: Fetch origin then Pull / Push
- Stash: Branch menu → Stash Changes
- Merge conflicts: Opens your merge tool for side-by-side fixes
VS Code Built-in
- Source Control (
Ctrl+Shift+G): stage, commit, push
- Branch picker (bottom-left): switch or create branches
- Timeline view (bottom of file explorer): local history
- Merge editor (3-way): accept current, incoming, or both
GitHub.com Web
- Quick dev: Press
. in any repo to open VS Code Web
- Edit files: Press
E on the repo page → edit → commit
- Blame view: Click Blame button in any file header
- Compare:
github.com/user/repo/compare/base...head
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
- Use
git commit --amend only on unpushed commits.
- Prefer
git pull --rebase to avoid merge bubbles.
- Run
git fetch --prune weekly to clean stale references.
- Set
git config --global pull.rebase true if your team rebases.
- Use
gh alias set to create custom CLI shortcuts.