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 3 sections
Git Branches and Worktrees in VS Code
Git branches enable you to work on different features or experiments simultaneously without affecting your main codebase. VS Code provides tools for branch management, Git worktrees for parallel development, and stash management for temporary changes.
This article covers working with branches, worktrees, and stashes in VS Code to manage parallel development work.
Working with branches
Branches are lightweight, movable pointers to specific commits in your Git history. They allow you to diverge from the main line of development and work on features independently.
For example, suppose you're working on a web application and need to add user authentication while also fixing a bug in the payment system. You can create two branches:
- feature/user-authentication - contains your login and signup functionality
- bugfix/payment-validation - contains fixes for payment processing errors
Each branch maintains its own set of changes without affecting the other. You can switch between branches to work on different tasks, and later merge the completed branches back into your main branch.
View current branch
The current branch appears in several places in VS Code:
- Status Bar: shows the current branch name and allows quick branch switching
- Repositories view: displays the current branch in the repository header
- Source Control Graph: visually represents branch relationships and history
Switch between branches
Switching to a different branch is called "checking out" a branch in Git terminology. When you check out a branch, Git updates your working directory to match that branch's state.
To switch to a different branch:
-
Select the branch name in the Status Bar, or run the Git: Checkout to command from the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)).
-
Choose from the list of available branches:
- Local branches: Branches that exist on your local machine
- Remote branches: Branches from the remote repository that you can check out locally
- Recent branches: Recently used branches
If you have uncommitted changes when switching branches, Git might prevent the switch to avoid losing work. Consider committing your changes or using a stash before switching.
Create new branches
Create a new branch to start working on a feature or experiment:
-
Select the branch name in the Status Bar or run Git: Create Branch from the Command Palette.
-
Enter a name for your new branch. Use descriptive names like feature/user-authentication or bugfix/login-error.
TipVS Code can generate random branch names for you. Configure this with the git.branchRandomName.enable and git.branchRandomName.dictionary settings.
-
Choose the source branch (usually main or develop) from which to create the new branch.
VS Code switches to the new branch after creation.
If you use the GitHub Pull Requests and Issues extension, you can create branches directly from GitHub issues, which gets you started working in a new local branch and automatically prefills the pull request for you.
Rename and delete branches
To rename the current branch:
- Run Git: Rename Branch from the Command Palette or select it from the More Actions (...) menu.
- Enter the new branch name.
To delete a branch:
- Switch to a different branch (you can't delete the currently active branch).
- Run Git: Delete Branch from the Command Palette or select it from the More Actions (...) menu.
- Select the branch to delete from the list.
You can also delete a remote branch by using the matching Delete Remote Branch action.
Deleting a branch permanently removes it from your local repository. Make sure the branch has been merged or you no longer need the changes.
Merge and publish branches
When your feature is complete, merge it back into the main branch:
- Switch to the target branch (usually main or develop).
- Run Git: Merge Branch from the Command Palette.
- Select the branch to merge.
To publish a branch to your remote repository, use the Publish Branch action.
VS Code shows the merge result in the Source Control view. If there are conflicts, VS Code highlights them and provides tools to resolve them. Learn more about resolving merge conflicts.
Working with Git worktrees
VS Code has built-in support for Git worktrees, making it easy to manage and work with multiple branches at the same time.
Understanding worktrees
A worktree is a separate checkout of a Git branch in its own directory. This allows you to have multiple working directories for the same repository, each on a different branch. Worktree functionality is especially useful for:
- Work on multiple features simultaneously in separate folders
- Run different versions of your application side by side
- Compare implementations across branches
Create a worktree
To create a new worktree in VS Code:
-
Open the Source Control Repositories view from the Source Control view.
-
Select your repository, open the More Actions (...) menu, and choose Worktrees > Create Worktree.
-
Follow the prompts to choose a branch and location for the new worktree.
VS Code creates a new folder for the worktree at the specified location and checks out the selected branch into that folder.
The new worktree appears as a separate entry in the Source Control Repositories view.
Switch between worktrees
VS Code can display multiple repositories (including worktrees) simultaneously:
- Each worktree appears as a separate repository in the Source Control Repositories view
- You can open multiple VS Code windows, each pointing to a different worktree
- Use File > Open Recent to quickly switch between worktree directories
Open a worktree
There are multiple ways to open a worktree:
-
Directly open the folder associated with the worktree in VS Code. VS Code automatically detects that it's a worktree of an existing repository.
-
Right-click the worktree in the Source Control Repositories view and select Open Worktree in New Window or Open Worktree in Current Window.
-
Run the Git: Open Worktree in Current Window or Git: Open Worktree in New Window command in the Command Palette and select the desired worktree.
Compare and migrate changes from a worktree
When you make changes in a worktree, you can compare those changes with your main workspace and bring worktree changes back into your main repository.
-
In the Source Control view, right-click a changed file in the worktree and select Compare with Workspace to see the differences side-by-side.
-
After reviewing, use the Migrate Worktree Changes command from the Command Palette to merge all changes from a worktree into your current workspace.
Next steps
- Staging and Committing - Learn about committing changes within branches
- Merge Conflicts - Handle conflicts when merging branches
- Repositories and Remotes - Work with remote branches and collaboration
- Collaborate on GitHub - Use GitHub pull requests with your branch workflow