π₯οΈ Git with VS Code
You've been running Git in VS Code's terminal all day. VS Code also has buttons for almost everything you typed. This page is a tour of those buttons, so you can pick whichever way feels natural on any given day.
π§ Same Git, two doors
The Source Control view doesn't have its own version control. Every button runs the same Git commands you already know, on the same repository. You can stage a file with a click and commit it from the terminal, or the other way round. Nothing gets out of sync.
On This Page
πΊοΈ A Tour of the Screen
Open your site folder (File β Open Folder) and click the Source Control icon in the Activity Bar, or press Ctrl+Shift+G (β+β§+G on a Mac). Here's what you're looking at:
- Source Control icon: a little number badge on it counts your uncommitted changes.
- Message box: your commit message goes here.
- β Commit button: commits whatever is under Staged Changes. It turns into Publish Branch or Sync Changes when there's something to push or pull.
- Staged Changes / Changes: the staging area and your working folder, exactly like
git status. The letter on the right tells you why a file is listed. - Graph: recent versions of VS Code draw your commit history right in this view (older versions show Incoming/Outgoing instead).
- Gutter bars: green = added lines, blue = changed lines, red triangle = deleted lines, compared with your last commit.
- Status bar: the current branch (the
*means uncommitted changes) and the sync indicator (commits to pull β and push β).
| Letter | Meaning | Terminal equivalent in git status |
|---|---|---|
| U | Untracked: a new file Git has never seen | Untracked files |
| A | Added: a new file you've staged | new file: |
| M | Modified since the last commit | modified: |
| D | Deleted | deleted: |
| ! or C | Conflict: needs your decision during a merge | both modified: |
π§ Before You Start
VS Code uses the Git you installed in Lesson 1. It doesn't bring its own. Two quick checks in the terminal (Ctrl+`) save a lot of confusion:
git --version
git config --global --list
You should see a version number and your user.name and user.email. If VS Code ever pops up "Make sure you configure your 'user.name' and 'user.email' in git", it means that second list is missing them. Run the two git config --global commands from Lesson 1 and try again.
β οΈ Open the folder, not a file
The Source Control view only works when you've opened the folder that contains the hidden .git folder, meaning your site folder. If you open a single file, or the folder above your site, VS Code will say there's no repository (or offer Initialize Repository, which you don't want if one already exists). Use File β Open Folder and pick my-website.
πΈ Stage & Commit
(appears under Changes)"] --> B["Click + to stage
(moves to Staged Changes)"] B --> C["Type a message"] C --> D["β Commit"] D --> E["Sync Changes
(push to GitHub)"]
- Stage one file: hover over it under Changes and click +. That's
git add <file>. - Stage everything: click the + on the Changes heading itself. That's
git add .. - Unstage: click β next to a staged file. That's
git restore --staged <file>. - Commit: type a message and click β Commit, or press Ctrl+Enter (β+Enter) in the message box.
- Stage just some lines: click the file to open its diff, select the lines you want, right-click, and choose Stage Selected Ranges. Handy when one file contains two unrelated changes that deserve two commits.
π‘ "There are no staged changes to commit"
If you click Commit with nothing staged, VS Code offers to stage everything and commit it in one go ("smart commit"). That's fine when every change belongs in the commit. If you're not sure, click Cancel, stage deliberately, and commit again. Small, focused commits make history far easier to read.
Amend the last commit: the β¦ (More Actions) menu at the top of the view β Commit β Commit Staged (Amend), the same as git commit --amend. Only amend commits you haven't pushed yet.
π Seeing & Undoing Changes
- See what changed: click any file in the Source Control view. VS Code opens a side-by-side diff: last commit on the left, your version on the right. That's
git diff, but easier to read. - Peek at one change: click a coloured gutter bar in the normal editor. A small inline diff appears with buttons to stage or revert just that block.
- Throw away changes to a file: hover over it and click the βΆ Discard Changes icon. That's
git restore <file>. VS Code asks you to confirm, because this can't be undone. - Undo the last commit (not pushed): β¦ β Commit β Undo Last Commit. The commit disappears but its changes come back as staged, so nothing is lost. (Behind the scenes this is
git reset --soft HEAD~1.) Once a commit is pushed, usegit revertinstead.
πΏ Branches & Merging
Click the branch name at the bottom-left of the status bar. A picker opens at the top of the window:
- + Create new branchβ¦: type a name, press Enter, and you're on it (
git switch -c). - Any branch in the list: switches to it (
git switch). Start typing to filter a long list.
To merge, first switch to the branch that should receive the work (usually main). Then open the Command Palette (Ctrl+Shift+P / β+β§+P), type Git: Merge, and pick the branch to bring in. The same command lives in β¦ β Branch. Labels shift a little between VS Code versions, so type "merge" and look for the Git one.
To delete a merged branch, type Git: Delete Branch in the Command Palette. Like git branch -d, it warns you if the branch isn't merged yet.
βοΈ Merge Conflicts
When a merge (or a git pull) conflicts, the file shows up under Merge Changes with a conflict marker. Open it and you'll see the two versions coloured differently, with clickable links above them:
Accept Current Change | Accept Incoming Change | Accept Both Changes | Compare Changes
- Current = the branch you're on (the
HEADhalf). - Incoming = the branch you're merging in.
- Both keeps both, one after the other. You'll often tidy up by hand afterwards.
For bigger conflicts, click Resolve in Merge Editor (bottom-right of the file). It shows Incoming and Current side by side on top and the Result underneath; tick the changes you want, edit the result if needed, then click Complete Merge.
When every conflicted file is resolved, stage the files (+) and click β Commit. VS Code fills in the merge message for you. Changed your mind part-way? git merge --abort in the terminal still works.
π°οΈ History: Timeline & Graph
- Timeline: open a file, then expand Timeline at the bottom of the Explorer view. It lists every commit that touched that file (like
git log -- <file>). Click one to see exactly what it changed. - Graph: in recent versions, the Source Control view has a Graph section showing commits and branches as a line-and-dots picture, similar to
git log --oneline --graph. Click a commit to see its files. - Hover blame: some versions (and GitLens, below) show who last changed the current line and in which commit, right in the editor.
π GitHub from VS Code
Signing in
Click the Accounts icon (the person at the bottom of the Activity Bar) β Sign in with GitHub. Your browser opens, you approve, and you're back. VS Code shares that sign-in with Git for pushes and pulls in most setups; if a push from the terminal still asks you to sign in, Git Credential Manager (Windows) or gh auth login handles it, just as in Lesson 5.
Publishing, syncing, cloning
- Publish Branch / Publish to GitHub: on a repository with no GitHub remote yet, this button creates the GitHub repo for you (you choose public or private) and pushes. It's an alternative to the
git remote add+git push -usteps from Lesson 5. - Sync Changes: pulls then pushes. The numbers next to it (β incoming, β outgoing) tell you what will move. VS Code asks for confirmation the first time; leave that on while you're learning.
- Git: Clone (Command Palette): paste a repository URL or pick one of your GitHub repos, choose a folder, and open it.
The GitHub Pull Requests extension
Install GitHub Pull Requests (published by GitHub) from the Extensions view (Ctrl+Shift+X). It adds a GitHub icon to the Activity Bar where you can:
- create a pull request from the branch you're on, without visiting github.com
- see your open PRs, their checks, and the Netlify Deploy Preview status
- read and reply to review comments next to the code they're about
- check out someone else's PR branch to try it locally
It's entirely optional. The github.com flow from Lesson 6 does the same job, and it's worth knowing that one first.
π§© Helpful Extensions
You don't need any of these, but many people like them. Search for them by name in the Extensions view, or install from the terminal:
| Extension | What it adds | Install command |
|---|---|---|
| GitHub Pull Requests | Pull requests and issues inside VS Code | code --install-extension GitHub.vscode-pull-request-github |
| GitLens | Inline blame, rich file/line history, commit search. The core is free; some views need a paid plan. | code --install-extension eamodio.gitlens |
| Git Graph | A detailed, clickable branch graph with right-click actions | code --install-extension mhutchie.git-graph |
β οΈ Buttons can do big things
Graph extensions put powerful actions (reset, rebase, force push, delete remote branch) one right-click away. If a menu item uses a word you haven't met yet, read about it on the Advanced Git page before clicking.
βοΈ Settings & Shortcuts
A few Git settings worth knowing (File β Preferences β Settings, then search "git."). These are sensible for a beginner:
// settings.json
{
// Check GitHub for new commits in the background, so Sync shows β counts
"git.autofetch": true,
// Ask before Sync pushes and pulls (keep this on while learning)
"git.confirmSync": true,
// Don't push automatically after every commit
"git.postCommitCommand": "none"
}
| Action | Windows / Linux | macOS |
|---|---|---|
| Source Control view | Ctrl+Shift+G | β+β§+G |
| Commit (in the message box) | Ctrl+Enter | β+Enter |
| Terminal | Ctrl+` | β+` |
| Command Palette | Ctrl+Shift+P | β+β§+P |
| Explorer | Ctrl+Shift+E | β+β§+E |
| Extensions | Ctrl+Shift+X | β+β§+X |
π©Ί Troubleshooting
| Problem | Fix |
|---|---|
| "Git not found" or no Source Control features | Install Git (Lesson 1), then fully quit and restart VS Code. Still stuck on Windows? Set the git.path setting to C:\Program Files\Git\cmd\git.exe. |
| "The folder currently open doesn't have a Git repository" | You've opened the wrong folder. File β Open Folder and choose the folder that holds your index.html (and the hidden .git). |
| "Make sure you configure your user.name and user.email" | Run the two git config --global commands from Lesson 1. |
| Push fails with an authentication error | Sign out and back in via the Accounts icon. If it persists, remove the saved GitHub login: Windows: Credential Manager β Windows Credentials, remove the git:https://github.com entry; macOS: Keychain Access, search "github.com" and delete it. Push again and sign in fresh. |
| A file I changed doesn't appear | It may be listed in .gitignore. Otherwise click the refresh icon in the Source Control view. |
| A button did something unexpected | Open View β Output and choose Git from the dropdown. It shows the exact Git commands VS Code ran and any error messages. |
π± Use whichever feels right
Some people live in the Source Control view, some never leave the terminal, and most mix the two. Knowing the commands means you understand what the buttons are doing; knowing the buttons makes everyday work quicker. You now have both.