Documentation
Topics Overview Overview Linux macOS Windows VS Code for the Web Raspberry Pi Network Additional Components Uninstall VS Code Tutorial Copilot Quickstart User Interface Personalize VS Code Install Extensions Tips and Tricks Intro Videos Overview Setup Quickstart Overview Language Models Context Tools Agents Customization Trust & Safety Overview Agents Tutorial Agents Window Planning Memory Tools Subagents Local Agents Copilot CLI Cloud Agents Third-Party Agents Overview Chat Sessions Add Context Inline Chat Review Edits Checkpoints Artifacts Panel Debug Chat Interactions Prompt Examples Overview Instructions Prompt Files Custom Agents Agent Skills Language Models MCP Hooks Plugins Context Engineering Customize AI Test-Driven Development Edit Notebooks with AI Test with AI Test Web Apps with Browser Tools Debug with AI MCP Dev Guide OpenTelemetry Monitoring Inline Suggestions Smart Actions Best Practices Security Troubleshooting FAQ Cheat Sheet Settings Reference MCP Configuration Workspace Context Display Language Layout Keyboard Shortcuts Settings Settings Sync Extension Marketplace Extension Runtime Security Themes Profiles Overview Voice Interactions Command Line Interface Telemetry Basic Editing IntelliSense Code Navigation Refactoring Snippets Overview Multi-Root Workspaces Workspace Trust Tasks Debugging Debug Configuration Testing Port Forwarding Integrated Browser Overview Quickstart Staging & Committing Branches & Worktrees Repositories & Remotes Merge Conflicts Collaborate on GitHub Troubleshooting FAQ Getting Started Tutorial Terminal Basics Terminal Profiles Shell Integration Appearance Advanced Overview Enterprise Policies AI Settings Extensions Telemetry Updates Overview JavaScript JSON HTML Emmet CSS, SCSS and Less TypeScript Markdown PowerShell C++ Java PHP Python Julia R Ruby Rust Go T-SQL C# .NET Swift Working with JavaScript Node.js Tutorial Node.js Debugging Deploy Node.js Apps Browser Debugging Angular Tutorial React Tutorial Vue Tutorial Debugging Recipes Performance Profiling Extensions Tutorial Transpiling Editing Refactoring Debugging Quick Start Tutorial Run Python Code Editing Linting Formatting Debugging Environments Testing Python Interactive Django Tutorial FastAPI Tutorial Flask Tutorial Create Containers Deploy Python Apps Python in the Web Settings Reference Getting Started Navigate and Edit Refactoring Formatting and Linting Project Management Build Tools Run and Debug Testing Spring Boot Modernizing Java Apps Application Servers Deploy Java Apps GUI Applications Extensions FAQ Intro Videos GCC on Linux GCC on Windows GCC on Windows Subsystem for Linux Clang on macOS Microsoft C++ on Windows Build with CMake CMake Tools on Linux CMake Quick Start C++ Dev Tools for Copilot Editing and Navigating Debugging Configure Debugging Refactoring Settings Reference Configure IntelliSense Configure IntelliSense for Cross-Compiling FAQ Intro Videos Get Started Navigate and Edit IntelliCode Refactoring Formatting and Linting Project Management Build Tools Package Management Run and Debug Testing FAQ Overview Node.js Python ASP.NET Core Debug Docker Compose Registries Deploy to Azure Choose a Dev Environment Customize Develop with Kubernetes Tips and Tricks Overview Jupyter Notebooks Data Science Tutorial Python Interactive Data Wrangler Quick Start Data Wrangler PyTorch Support Azure Machine Learning Manage Jupyter Kernels Jupyter Notebooks on the Web Data Science in Microsoft Fabric Foundry Toolkit Overview Foundry Toolkit Copilot Tools Create Agents Models Playground Agent Builder Agent Inspector Evaluation Tool Catalog Fine-Tuning (Automated Setup) Fine-Tuning (Project Template) Model Conversion Tracing Profiling (Windows ML) FAQ File Structure Manual Model Conversion Manual Model Conversion on GPU Setup Environment Without Foundry Toolkit Template Project Migrating from Visualizer to Agent Inspector Overview Getting Started Resources View Deployment VS Code for the Web - Azure Containers Azure Kubernetes Service Kubernetes MongoDB Remote Debugging for Node.js Overview SSH Dev Containers Windows Subsystem for Linux GitHub Codespaces VS Code Server Tunnels SSH Tutorial WSL Tutorial Tips and Tricks FAQ Overview Tutorial Attach to Container Create Dev Container Advanced Containers devcontainer.json Dev Container CLI Tips and Tricks FAQ Default Keyboard Shortcuts Default Settings Substitution Variables Tasks SchemaOn this page there are 6 sections
Quickstart: use source control in VS Code
Get up and running with Git in Visual Studio Code in minutes. This guide covers the essentials of setting up a repository, saving your changes, and syncing your code.
Prerequisites
-
Install Git: make sure Git is installed on your computer. Download Git
-
Open VS Code: make sure you have the latest version of Visual Studio Code installed.
Step 1: Open a project
You can start with an existing Git repository or a local project folder.
Option A: Clone a repository locally
Clone a repository if you want to work on code that is already hosted on GitHub, Azure DevOps, or another Git provider. If you have previously cloned the repository, you can open the folder directly in VS Code and VS Code will detect the Git repository automatically.
To clone a repository in VS Code:
-
Open the Source Control view (⌃⇧G (Windows, Linux Ctrl+Shift+G)) and select Clone Repository
Alternatively, open the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)) and enter Git: Clone.
-
Enter the repository URL (for example, https://github.com/microsoft/PowerToys)
If you're cloning from GitHub, you can also select Clone from GitHub and sign in to your GitHub account to see a list of your repositories.
-
Select a parent folder on your computer to save the project
-
Select Open when prompted to open the cloned repository in VS Code
-
Confirm whether you trust the repository in the Workspace Trust dialog
CautionOnly trust repositories from sources you know. Untrusted code can potentially harm your computer.
Option B: Initialize a repository in a local folder
To start a new project with Git, you can initialize a repository in an existing local folder. This option creates a new Git repository in your folder to track changes.
-
Open your project folder in VS Code (File > Open Folder...).
-
Open the Source Control view (⌃⇧G (Windows, Linux Ctrl+Shift+G)) and select Initialize Repository
Alternatively, open the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)) and enter Git: Initialize Repository.
Step 2: Make changes and review
Git tracks changes to files in your project. The Source Control view in VS Code is your hub for managing these changes without using the command line.
Let's make a simple code change and use the Source Control view and diff editor to review it.
-
Edit an existing file in your project, and save it.
If you've just initialized a new repository, you can move on to the next step.
-
Open the Source Control view (⌃⇧G (Windows, Linux Ctrl+Shift+G)).
Notice that the changed file(s) are listed under Changes with a "U" (untracked) or "M" (modified) icon next to them. The source control icon in the Activity Bar also shows a badge with the number of affected files.
-
To review the changes to a file, select it in the Source Control view to open a diff editor.
A diff editor shows the differences between the current version of the file and the last committed version. If the window is wide enough, the diff editor displays a side-by-side comparison, otherwise the changes are shown inline.
TipIf you have a Copilot subscription, select the Code Review button in the Source Control view to perform an AI-powered code review of your changes before committing them.
Step 3: Stage and commit
Git uses a two-step process to save changes: Stage (prepare) and Commit (save). In the Source Control view, changes are first listed under Changes and after staging them, they move to Staged Changes where they are ready to be committed.
-
To stage your changes, do one of the following:
-
Hover over a file in the Changes list and select + (plus) to stage it
-
Right-click a file in the Changes list and select Stage Changes
-
Hover over the Changes header and select the + (plus) button to stage all changes at once
-
-
(Optional) You can unstage changes or discard changes if needed:
-
To unstage a file, hover over it in the Staged Changes list and select the - (minus) button
-
To discard changes to a file, right-click it in the Changes list and select Discard Changes
-
-
To commit your staged changes you can provide a commit message.
-
Enter a commit message in the text box at the top of the Source Control view.
You can also use AI to generate a commit message based on your staged changes by selecting the sparkle icon in the commit message input box.
-
Select Commit to commit your changes to your Git history
After committing, the staged changes are cleared from the Source Control view and saved in your local Git history.
NoteOnly staged changes are included in a commit. If you have unstaged changes, they remain listed under Changes for future commits.
-
-
To view your commit history, select the Source Control Graph in the Source Control view.
Step 4: Sync with the server
If your repository is connected to a remote server (for example, GitHub or Azure DevOps), you can sync your local commits with the remote repository.
-
Open the Source Control view (⌃⇧G (Windows, Linux Ctrl+Shift+G))
-
Select Sync Changes to pull the latest changes from the remote and push your local commits
Alternatively, the Status Bar shows sync status and enables you to sync changes by selecting the sync icon (rotating arrows).
-
Select it to pull new changes from the server and push your commits.
-
To pull or push individually, select the ellipsis menu (...) in the Source Control view and choose Pull or Push.
If you started with a local folder (Option B) and want to save it to GitHub, use the Publish to GitHub button in the Source Control view.
Next steps
Now that you know the basics, explore more features:
- Branches and Worktrees - Learn about branch management and parallel development.
- Repositories and Remotes - Learn about cloning, publishing, and syncing with remote repositories.
- Resolve Merge Conflicts - Learn how to handle conflicts when merging branches.
- Working with GitHub - Learn about Pull Requests and Issues.
- Troubleshooting - Diagnose and resolve Git issues.
- Source Control Overview - Full reference for source control features.