Skip to main content

πŸ–₯️ 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:

Simplified VS Code window with the Source Control view open The Activity Bar on the far left with the Source Control icon selected; the Source Control view with a message box, a Commit button, a Staged Changes group containing style.css marked M, and a Changes group containing about.html marked M and gallery.html marked U; an editor with coloured bars in the gutter; and the status bar showing the branch name main and a sync indicator. my-website β€” Visual Studio Code SOURCE CONTROL Rewrite about page intro βœ“ Commit βŒ„ Staged Changes style.css M βŒ„ Changes about.html M gallery.html U βŒ„ Graph Add gallery page Add contact page about.html βŽ‡ main* ⟳ 0↓ 1↑ 1 2 3 4 5 6 7
A simplified sketch, not a screenshot. Your theme, icons, and exact layout will differ a little.
  1. Source Control icon: a little number badge on it counts your uncommitted changes.
  2. Message box: your commit message goes here.
  3. βœ“ Commit button: commits whatever is under Staged Changes. It turns into Publish Branch or Sync Changes when there's something to push or pull.
  4. 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.
  5. Graph: recent versions of VS Code draw your commit history right in this view (older versions show Incoming/Outgoing instead).
  6. Gutter bars: green = added lines, blue = changed lines, red triangle = deleted lines, compared with your last commit.
  7. Status bar: the current branch (the * means uncommitted changes) and the sync indicator (commits to pull ↓ and push ↑).
LetterMeaningTerminal equivalent in git status
UUntracked: a new file Git has never seenUntracked files
AAdded: a new file you've stagednew file:
MModified since the last commitmodified:
DDeleteddeleted:
! or CConflict: needs your decision during a mergeboth 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

flowchart LR A["Save a file
(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, use git revert instead.

🌿 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 HEAD half).
  • 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 -u steps 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:

ExtensionWhat it addsInstall command
GitHub Pull RequestsPull requests and issues inside VS Codecode --install-extension GitHub.vscode-pull-request-github
GitLensInline blame, rich file/line history, commit search. The core is free; some views need a paid plan.code --install-extension eamodio.gitlens
Git GraphA detailed, clickable branch graph with right-click actionscode --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"
}
ActionWindows / LinuxmacOS
Source Control viewCtrl+Shift+GβŒƒ+⇧+G
Commit (in the message box)Ctrl+Enter⌘+Enter
TerminalCtrl+`βŒƒ+`
Command PaletteCtrl+Shift+P⌘+⇧+P
ExplorerCtrl+Shift+E⌘+⇧+E
ExtensionsCtrl+Shift+X⌘+⇧+X

🩺 Troubleshooting

ProblemFix
"Git not found" or no Source Control featuresInstall 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 errorSign 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 appearIt may be listed in .gitignore. Otherwise click the refresh icon in the Source Control view.
A button did something unexpectedOpen 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.