The Source Control view
Beginner VS Code UI
Why this matters
This one panel replaces git status, git diff, git add, git commit, git pull and git push. Reading it accurately is most of what makes the editor usable for Git, and it takes about ten minutes to learn.
The panel
Open it with the Source Control icon in the Activity Bar, or ⌃⇧G (Ctrl+Shift+G on Windows and Linux).
The sections
| Section | Contains | In Git terms |
|---|---|---|
| Staged Changes | What the next commit will include | The staging area (lesson 2.2) |
| Changes | Modified and untracked files not staged yet | The working tree |
| Merge Changes | Files with conflicts, during a merge | Unmerged paths (lesson 15.7) |
The split between the first two is the whole point of the panel. If it looks like unnecessary bureaucracy, lesson 5.3 is the argument for it.
The marks
A single letter after each file name, which is git status's letter:
| Mark | Means |
|---|---|
| M | Modified |
| U | Untracked, a file Git has never seen |
| A | Added: staged for the first time |
| D | Deleted |
| R | Renamed |
| C | Conflict |
The buttons
Hovering a file shows up to three:
| Button | Does | Command |
|---|---|---|
| + | Stage this file | git add <file> |
| ↺ | Discard changes | git restore <file> — permanent |
| − | Unstage (on a staged file) | git restore --staged <file> |
The header of each section has the same buttons for everything in it. The discard button is the one to be careful with: it destroys work Git never recorded, and it is next to the stage button (lesson 12.9). VS Code asks for confirmation, and the confirmation is worth reading.
Above the lists sit the message box and Commit, and below them Sync Changes, which is git pull followed by git push. Its label carries the counts: 1↓ 2↑ means one commit to pull and two to push.
Clicking a file opens the diff
This surprises people: clicking a file name in Source Control opens a side-by-side comparison, not the file. The left side is the previous version, the right is yours, and the right side is editable, so you can fix something while reviewing it.
To open the file itself instead, click it in the Explorer, or use the Open File button on the diff.
The rest of the panel
| Feature | Where | Does |
|---|---|---|
| Source Control Graph | Below the file lists | The commit history as a graph, with branches |
| Timeline | In the Explorer, below the file tree | One file's history, plus VS Code's own local saves |
| Stashes | The … menu → Stash | git stash and friends (command page) |
| Views and More Actions (…) | Top right of the panel | Everything without a button: pull, push, fetch, checkout, tags, remotes |
The Timeline deserves a mention as a safety net: it records file saves independently of Git, so it can sometimes recover an edit you discarded before committing, which Git cannot (lesson 12.1).
How to do it
The panel, as commands:
$ git status # the two sections
$ git diff <file> # what clicking a file shows
$ git add <file> # +
$ git restore <file> # ↺
$ git restore --staged <file> # −
$ git commit -m "…" # the message box and Commit
$ git pull && git push # Sync ChangesThe Command Palette has all of it, and the names survive interface changes:
- Git: Stage Changes, Git: Unstage Changes, Git: Discard Changes
- Git: Commit, Git: Commit Staged
- Git: Pull, Git: Push, Git: Sync
- Git: Stash, Git: Pop Latest Stash
- Git: Open Changes for the diff of the current file
The equivalent is the Commit tool window plus the Git tool window; IntelliJ splits what VS Code combines. See lesson 16.4.
Nothing here is platform-specific: this panel talks to your local repository. The GitLab Workflow extension adds merge requests and pipelines on top (lesson 15.8).
The same, with the GitHub Pull Requests and Issues extension.
Common mistakes
- Clicking ↺ instead of +. Discard is permanent; read the confirmation.
- Committing with nothing staged, which with smart commit on commits everything (lesson 15.1).
- Expecting a file name to open the file. It opens the diff.
- Ignoring the Sync counts, then being surprised by a rejected push.
- Looking for pull and push as buttons. They are in the … menu, or use Sync.
Try it yourself
Goal: read the panel as fluently as git status.
- In your practice project, modify two files and create a third new file.
- Open the Source Control view and identify each mark: two M and one U.
- Stage one file with +, and watch it move to Staged Changes.
- Click each file name and read the diff; note that the right-hand side is editable.
- Commit only the staged file, then run
git log --oneline -1andgit statusin the integrated terminal to confirm the panel and the commands agree.
Expected result: one commit containing one file, with the other two still waiting, and the terminal confirming exactly what the panel showed.
Show solution
Step 5 is the point of the exercise. The panel is a view of the same repository the commands read, so the two can never disagree. Checking once builds the confidence to use whichever is faster in the moment.