Git Branches
Git enables you to branch out from your main codebase, creating parallel development paths that revolutionize how teams collaborate. This branching system provides unparalleled flexibility in your development workflow, allowing multiple developers to work simultaneously without interfering with each other's progress or the stability of your production code.

Consider this real-world scenario that demonstrates the power of Git branches: You're deep into developing a complex new feature for your application when an urgent bug report comes in—something that needs to be fixed and deployed immediately. Without branches, you'd face a dilemma: either abandon your unfinished work or deploy unstable code. With Git branches, you simply switch back to your main branch, implement the hotfix, and deploy it to production. Then you seamlessly return to your feature branch to continue development. When your new feature is complete and tested, you merge it into the main branch, preserving both your urgent fix and your new functionality. This workflow prevents the chaos that often accompanies concurrent development efforts.
Core Git Branch Benefits
Parallel Development
Work on multiple features simultaneously without interfering with the main codebase. Switch between different development contexts instantly.
Safe Experimentation
Test new ideas and approaches without risk to production code. Easily discard failed experiments or merge successful ones.
Team Collaboration
Multiple developers can contribute to the same project without stepping on each other's work. Merge changes when ready.
Working on a Branch: Commit, Push, Pull, Etc.
Every Git operation you perform—whether committing changes, pushing to remote repositories, or pulling updates—occurs within the context of your current branch. This branch-specific behavior is fundamental to Git's design and critical to maintaining clean project history. Always verify you're on the correct branch before executing any Git commands, as working on the wrong branch is one of the most common sources of confusion and merge conflicts in team environments.
Every Git command you execute operates within the context of your current branch. Always verify which branch you're on before committing, pushing, or pulling to avoid unintended changes to the wrong branch.
See What Branch You're on
Visual Studio Code displays your current branch name in the bottom-left corner of the window. The default branch name varies by platform and Git configuration—while older repositories may show master, most modern repositories use main as the default branch name, reflecting current industry best practices around inclusive terminology.
Identifying Your Current Branch in VS Code
Locate Branch Indicator
Look at the bottom left corner of the Visual Studio Code window where the current branch name is displayed
Verify Branch Context
The default branch name is typically 'master' but confirm you're on the intended branch before making changes
Create a New Branch
- Click the current branch name in the bottom-left corner of the Visual Studio Code window.
- In the command palette that appears at the top of the window, select + Create new branch.
Enter a descriptive name for your new branch and press Return (Mac) or Enter (Windows). Use clear, purposeful naming conventions like feature/user-authentication or bugfix/header-alignment to maintain project organization.
You're now working on your new branch and ready to make commits that won't affect your main codebase.
Creating a New Branch in VS Code
Access Branch Menu
Click the current branch name at the bottom left of VS Code window to open the branch selection panel
Select Create Option
Choose '+ Create new branch' from the panel that appears at the top of the window
Name Your Branch
Type a descriptive name for your new branch and press Return (Mac) or Enter (Windows) to create it
Start Working
You're now on the new branch and ready to make commits specific to this development context
Switch to a Branch in Your Local Repo
Switching between local branches allows you to context-switch between different features or experiments instantly.
- Click the current branch name in the bottom-left corner of the Visual Studio Code window.
- From the branch list that appears in the command palette, select the branch you want to switch to. Visual Studio Code will instantly update your workspace to reflect that branch's state.
Local Branch Switching Checklist
Opens the branch selection panel at the top of the window
All locally available branches will be listed for selection
Click the branch you want to switch to and VS Code will change your working context
Switch to a Branch in a Remote Repo
Working with remote branches enables collaboration with team members and access to work stored in your remote repository.
- First, fetch the latest branch information from your remote repository. In the Source Control panel
, click the More Actions button
, navigate to Pull, Push, and select Fetch. - Click the current branch name in the bottom-left corner of the window.
- In the branch list, remote branches are prefixed with origin/ (or your remote's name). Select the remote branch you want to work with—Visual Studio Code will automatically create a local tracking branch.
Accessing Remote Branches
Fetch Remote Data
In Source Control panel, click More Actions button, navigate to Pull, Push and select Fetch to get latest remote branch information
Open Branch Panel
Click the current branch name at bottom left of VS Code to view all available branches
Identify Remote Branches
Remote branches are prefixed with 'origin/' in the branch list panel
Switch to Remote Branch
Select the origin/ branch you want to work with from the available options
Fetch Versus Pull
Fetch downloads the latest data from your remote repository without modifying your working files. This allows you to see what changes exist remotely before deciding how to integrate them.
Pull combines fetch and merge operations: it downloads new data from the remote repository and immediately attempts to merge those changes into your current branch. Use pull when you're confident about integrating remote changes.
Fetch vs Pull Operations
| Feature | Fetch | Pull |
|---|---|---|
| Data Download | Downloads new data from remote | Downloads new data from remote |
| Local Integration | Does not merge into files | Merges data into your files |
| Working Directory | Leaves files unchanged | Updates your working files |
| Safety Level | Safe, non-destructive | Can create merge conflicts |
Merge a Branch
Merging integrates changes from one branch into another, typically combining feature work back into your main development branch.
Switch to the target branch—the branch that will receive the merged changes. In most workflows, this means switching to your main or master branch. Click the current branch name in the bottom-left corner and select your target branch.
Professional teams often use pull requests or merge requests instead of direct merges to maintain code quality through peer review processes.
- Ensure your working directory is clean by checking the Source Control panel
for any uncommitted changes. Commit or stash any pending work before proceeding. Execute the merge by clicking the More Actions button
in the Source Control panel
and selecting Branch > Merge Branch.Choose the source branch you want to merge into your current branch.
NOTE: Merge conflicts may occur when Git cannot automatically reconcile differences between branches. When this happens, refer to How to Handle Merge Conflicts for resolution strategies.
Branch Merging Process
Switch to Target Branch
Navigate to the branch that will receive the merged changes, typically the master branch
Verify Clean State
Ensure Source Control panel shows no uncommitted changes that need to be committed first
Access Merge Options
Click More Actions button in Source Control panel, then select Branch > Merge Branch from the menu
Select Source Branch
Choose the branch you want to merge into your current branch and confirm the merge operation
Merging branches may result in conflicts when the same code has been modified in different ways. Be prepared to resolve conflicts manually when they occur during the merge process.
Delete a Local Branch
Maintaining a clean branch structure improves repository navigation and reduces confusion. Delete branches that have served their purpose and been successfully merged.
- Switch away from the branch you want to delete—Git prevents deletion of the currently active branch as a safety measure.
Access the branch management menu by clicking the More Actions button
in the Source Control panel
and selecting Branch > Delete Branch.Select the branch you want to delete from the list.
Confirm the deletion when prompted. Remember that this only removes the local branch—remote branches require separate deletion if you want to clean up your remote repository as well.
Safe Branch Deletion Process
You cannot delete the branch you're currently working on
Click the More Actions button to reveal additional branch management options
Select the deletion option from the nested branch management menu
Choose the specific branch to delete and confirm the permanent removal