Cheat Sheet

Each row shows the terminal command, the VS Code way, and a one-line meaning. Tap a command to copy it.

One-time setup

Terminal: Ctrl+`
Check Git is installed
Run in terminal
Set the name on your commits
Run in terminal
Set the email on your commits
Run in terminal
New repos start on “main”
Run in terminal
Review everything you’ve set

Starting a repo

Source Control → Initialize Repository
Start tracking the current folder
Command Palette → Git: Clone
Download a repo from GitHub
Look at the Source Control panel
See what changed / which branch

The daily save cycle

Click + next to "Changes"
Stage your changes for the next commit
Type message → click ✓ Commit
Save a snapshot with a note
Click a file to see the diff
Review exactly what changed
Use the Git Graph / Timeline view
See the commit history

Viewing history

Git Graph extension
Visualise branches & merges
Click a commit in Git Graph
See one commit’s changes
Compare in Git Graph
Differences between two branches
GitLens inline blame
Who last changed each line

Syncing with GitHub

Sync Changes (↻) in the status bar
Upload your commits to GitHub
Sync Changes (↻) in the status bar
Download others’ commits
Source Control → Publish to GitHub
Connect a local repo to GitHub

Pull requests & forks

GitHub PR extension → Create Pull Request
Open a PR from your branch
PR extension → Checkout
Try someone’s PR locally
github.com → Fork button
Fork a repo and clone your copy
Source Control → … → Remote → Add Remote
Link your fork to the original
github.com → Sync fork → Update branch
Catch your fork up

Branching & merging

Status bar → Create new branch
Create and move to a new branch
Status bar → pick the branch
Switch to an existing branch
Status bar → branch list
List all branches
Command Palette → Git: Merge Branch
Bring a branch into the current one
Command Palette → Git: Abort Merge
Cancel a merge in progress
Branch picker → Delete Branch
Delete a merged branch

Stashing

Source Control → … → Stash
Shelve uncommitted changes
… → Stash → Pop Stash
Bring the latest stash back
Stash list in the … menu
See what you’ve shelved
… → Stash (Include Untracked)
Stash new files too

Tags & releases

Command Palette → Git: Create Tag
Mark a version (annotated)
Push (Follow Tags)
Send tags to GitHub
GitHub → Releases → Draft
Publish a release

When Git complains

Sync Changes (↻)
“[rejected] … (fetch first)” — GitHub has commits you don’t; pull, then push
Accounts icon → sign in with GitHub
“Support for password authentication was removed” — use a token
Add to .gitignore first
“GH001 … exceeds file size limit” — untrack the big stuff
Status bar → CRLF/LF
“LF will be replaced by CRLF” — harmless Windows warning
Status bar → Create new branch
“You are in detached HEAD state” — pin your work to a branch
Git: Rename Branch…
Rename master to main

Undo & rescue

Source Control → Discard Changes
Throw away unsaved edits to a file
Click − (Unstage)
Unstage a file (keep the edits)
… → Commit → Commit (Amend)
Fix the last commit or its message
… → Commit → Undo Last Commit
Un-commit, keep the changes
Terminal (destructive)
Delete the last commit AND its changes
Command Palette → Git: Revert
Safely undo a pushed commit
Discard untracked changes
Delete untracked files & folders
Terminal
Find “lost” commits to recover them
Terminal (GitLens adds a UI)
Copy a commit onto this branch

Lost? When something looks wrong, run git status first — it almost always tells you what to do next. And remember: committed work is very hard to truly lose, so experiment freely.

FAQ

Frequently Asked Questions

What are the most important Git commands for beginners?
The daily loop: git pull, edit your files, git add ., git commit -m "message", then git push. Add git status, git switch and git merge and you can handle most everyday work.
What should I do when something goes wrong in Git?
Run git status first — it almost always tells you the next step. Then match your exact error to a Fix-it chapter: discard, undo commits, or push rejected.
How do I undo the last commit?
git reset HEAD~1 un-commits but keeps your changes. For a commit you've already pushed, use git revert <commit> instead.