How to Create, Switch, and Merge Git Branches in VS Code

Create, switch, and merge Git branches in VS Code using the Status Bar and Command Palette. Work on features in isolation and merge them back when ready.

6 min read

Branches let you work on features, fixes, and experiments in isolation without touching the main codebase. VS Code gives you a visual way to create, switch, and merge branches from the Status Bar and Command Palette.

If you are new to Git in VS Code, start with /vscode/how-to-stage-commit-push-and-pull-changes-in-vs-code to learn the commit workflow first.

See your current branch

The current branch name is always visible in the Status Bar, at the bottom-left corner of the window. Select it to open the branch menu, which lists:

  • Local branches on your machine
  • Remote branches from GitHub or other remotes
  • Recently used branches

The Source Control Graph in the Source Control view also shows your branch visually, including how it relates to other branches and the remote.

Create a new branch

Start from the Status Bar

Select the branch name in the Status Bar. In the menu that opens, choose Create new branch.

Name your branch

Type a descriptive name. Use short, clear names like feature/user-auth or fix/login-error. Press Enter.

Pick the source branch

VS Code asks which branch to base your new branch on. Usually this is main or develop. Select it from the list.

VS Code creates the branch and switches to it immediately. The Status Bar updates to show the new branch name. You can also create a branch through the Command Palette: run Git: Create Branch and follow the same prompts.

If you have the GitHub Pull Requests extension installed, you can create a branch directly from a GitHub issue. Right-click the issue and select Start Working on Issue. VS Code creates a branch and prefills the pull request details.

Switch between branches

Select the branch name in the Status Bar and pick any branch from the list. VS Code checks out that branch and updates your files to match its state.

You can also run Git: Checkout to from the Command Palette for the same result. If you have uncommitted changes that conflict with the target branch, Git blocks the switch. Commit or stash your work first.

Merge a branch

When your feature is complete, merge it back into the main branch.

Switch to the target branch

Select the branch name in the Status Bar and switch to the branch you want to merge into (usually main).

Run the merge command

Open the Command Palette and run Git: Merge Branch.

Select the source branch

Pick the feature branch you want to merge from the list.

VS Code merges the branch and shows the result. If the merge succeeds with no conflicts, the changes from the feature branch are now part of the target branch. Push the merged result with Sync Changes.

If there are conflicts, VS Code highlights the conflicting files in the Source Control view under a Merge Changes section. Open any file to resolve conflicts inline or use the 3-way merge editor. Read /vscode/how-to-resolve-git-merge-conflicts-with-the-vs-code-merge-editor for step-by-step guidance.

Publish a branch to GitHub

New branches exist only on your machine until you publish them. In the Source Control view, select the Publish Branch button to push the branch to GitHub and set the upstream. After publishing, the button changes to Sync Changes for normal push and pull.

Rename or delete a branch

To rename the current branch, run Git: Rename Branch from the Command Palette and enter the new name.

To delete a branch, first switch to a different branch (you cannot delete the active one). Then run Git: Delete Branch from the Command Palette and pick the branch to remove. You can also delete the matching remote branch with the Delete Remote Branch action.

Deleting a branch permanently removes it. Make sure the branch has been merged or you no longer need its changes before deleting.

Next, use Git: Merge Branch when you are ready, and learn how to handle conflicts if they come up.

Rune AI

Rune AI

Key Insights

  • Select the branch name in the Status Bar to see all branches and switch between them.
  • Create a new branch with Git: Create Branch or by selecting the branch indicator and choosing Create new branch.
  • Merge a completed branch with Git: Merge Branch from the Command Palette.
  • Publish a local branch to GitHub with the Publish Branch button in the Source Control view.
  • Delete old branches with Git: Delete Branch after switching away from them.
RunePowered by Rune AI

Frequently Asked Questions

What happens to my uncommitted changes when I switch branches?

Git may prevent the switch if your changes conflict with the target branch. Commit or stash your changes first. VS Code warns you before switching if there is a risk of losing work.

How do I delete a branch after merging it?

Switch to a different branch first (you cannot delete the active branch). Then run **Git: Delete Branch** from the Command Palette and select the branch to remove. You can also delete the remote branch with the **Delete Remote Branch** action.

Can I rename a branch in VS Code?

Yes. Run **Git: Rename Branch** from the Command Palette and enter the new name. The rename applies to your local branch only.

What is the difference between merge and rebase?

Merge creates a merge commit that joins two branch histories. Rebase replays your commits on top of the target branch, creating a linear history. VS Code supports merge through the Command Palette. For rebase, use the **Git: Rebase Branch...** command or the terminal.

Conclusion

Branches let you work on features and fixes without affecting the main codebase. VS Code makes it easy to create, switch, and merge branches from the Status Bar and Command Palette, so you can focus on writing code instead of remembering Git commands.