Check Git and open your existing repository
You need:
- VS Code installed.
- Git installed on your PC; VS Code’s built-in Git integration uses that installation.
- An existing local Git repository.
- At least one saved addition, modification, or deletion to review.
You do not need a GitHub account or a remote repository to stage changes locally. This procedure uses VS Code’s built-in Git support, not an additional source-control extension.
- In VS Code, select File > Open Folder... and open your repository’s folder.
- Select Terminal > New Terminal.
- Check that Git is available:
git --version
Expect a Git version number. If the command is not found after installing Git, close and reopen VS Code, then try again.
- In the terminal, make sure you are working inside the intended repository, then run:
git status
Git should report the repository’s current state. If it says this is not a Git repository, check the folder before proceeding. Do not initialize a new repository merely to make an existing project appear in Source Control.
No Windows restart is needed for staging. Restarting VS Code may be necessary when it needs to detect a newly installed Git executable.
Review saved changes before staging
Saving, staging, and committing are separate operations. Saving writes an edit to disk. Staging selects content for the next commit. Committing records that staged snapshot in local history; pushing uploads commits to a remote repository.
- Save the file you want to review with Ctrl+S. Repeat for other edited files.
- Press Ctrl+Shift+G to open Source Control.
- Look under Changes. Common indicators include:
- M: Modified.
- U: Untracked—a new file Git is not yet tracking.
- D: Deleted.
- Select a filename in Changes to inspect its pending edits. Selecting a file in Staged Changes, by contrast, reviews content already selected for the next commit.
Review from the Source Control list rather than relying only on the file’s normal editor tab. The diff editor shows what changed, making it easier to spot unrelated edits before selecting them. VS Code also allows edits on the pending-changes side of a diff; save any corrections before continuing.
Treat a new file as a separate review item. Its contents have not previously been recorded in this repository, so check the entire file rather than looking only for a small modification.
Stage whole files or all pending changes
Choose whole-file staging when every saved change in a file belongs in the same commit.
- Under Changes, hover over the file.
- Select its + icon, or right-click it and choose Stage Changes.
- Find the file under Staged Changes.
- Select that staged entry to review your selection.
To stage everything listed under Changes, hover over the Changes heading and select its + icon. Review the list first: bulk staging is appropriate only when you want all those pending changes included together.
Staging captures the file’s content at that moment. It does not create a live selection that automatically incorporates every later edit. If you stage a file and then change it again, the newer edits remain unstaged until you stage them too. This is why checking the staged version matters even when you have already inspected the working file.
You can stop here if whole-file staging meets your needs. Do not select Commit merely to confirm staging; the staged list and the verification checks below are enough.
Stage only selected lines in a file
Partial staging is useful when one text file contains changes that belong in different commits—for example, a bug fix and unrelated wording changes. Keep the intended commit focused rather than staging the file simply because part of it is ready.
- Select the file under Changes to open its diff.
- Select the changed lines you want to include.
- Right-click the selection and choose Stage Selected Ranges.
Alternatively, with the selection active, press Ctrl+Shift+P and run:
Git: Stage Selected Ranges
- Review the file under Staged Changes, then inspect its remaining entry under Changes.
Use the range command rather than the + beside the filename when you want only part of that file. The file-level action selects the whole file’s pending changes.
For a practical check, compare the two entries after staging: the staged view should contain the intended change, while the unstaged view should retain the edits you left out. A filename appearing in both sections is expected when it has both staged and unstaged content—not evidence that VS Code created a duplicate file.
Unstage changes without losing your edits
Do not use Discard Changes or a Revert control to remove something from staging. Those actions can remove working edits; unstaging preserves them. Recovery after discarding work is not guaranteed.
- Find the file under Staged Changes.
- Hover over it and select −, or right-click it and choose Unstage Changes.
- Confirm that its pending changes are back under Changes.
- Reopen the file to verify your edits are still present.
To remove only part of a staged file, open its staged diff, select the relevant lines, and use the Unstage button in the gutter beside the selection.
If your selection became confusing, unstage the file and repeat the selection process. There is no need to delete edits, reset the repository, or alter commit history to correct an ordinary staging mistake.
Verify exactly what the next commit will contain
Use Git’s own read-only checks when you want confirmation beyond the graphical view.
- Select Terminal > New Terminal and make sure the terminal is in the repository.
- Run:
git status
Check Changes to be committed for staged files. Changes not staged for commit identifies remaining modifications to tracked files; Untracked files lists new files not yet staged. A partially staged file can be represented in both the staged and unstaged groups.
- Inspect the staged patch:
git diff --cached
This compares the index—the staging area—with the current commit. It is the important check for the content selected for your next ordinary commit. In a repository without a first commit, it shows the staged content.
- Inspect remaining unstaged changes to tracked files:
git diff
This compares working files with the staging area. It does not show the contents of untracked files; check git status for those.
Success means the staged diff contains the intended work and excludes unrelated edits. An empty unstaged diff alone is not proof that everything is staged, because untracked files require the separate status check.
Troubleshoot missing files, unavailable actions, and staging errors
Git works poorly or the repository does not appear
Run git --version again. If Git is missing, install it and restart VS Code. If Git works in the terminal but VS Code cannot detect it, inspect the Git Output window before changing configuration.
Also confirm that you opened the repository folder, not an unrelated parent folder or a standalone file. An existing checkout should be opened as a repository rather than initialized again.
A saved new file is missing from Changes
First check git status in the intended repository. If a new file remains absent, check whether an ignore rule applies. Replace the example path below with the file’s path relative to the repository:
git check-ignore -v -- "path/to/file.txt"
For an ignored file, verbose output identifies the matching rule and where it is defined. No output does not establish that VS Code is broken; the file may not be ignored, and tracked files are not reported by this command by default. Do not force-add an ignored file until you understand why it was excluded.
Stage Selected Ranges is unavailable or stages the wrong selection
Return to Changes, open the file’s diff, and select the actual changed text before running Git: Stage Selected Ranges. Avoid invoking the file-level staging action when your intention is line-level selection. If the result is wrong, unstage the file, then try again with a smaller selection.
A file appears in both sections
Inspect both entries before taking action. This normally means you staged one version and then edited the file again, or deliberately staged only part of it. Stage the remaining changes only if they belong in the same commit; otherwise leave them under Changes.
A Git operation reports an error
- Press Ctrl+Shift+P.
- Run Git: Show Git Output.
- Find the failing command and its first error message.
- If escalating the issue, include that error and the Git version, but remove private repository paths, remote addresses, credentials, and sensitive project information before sharing logs.