How to Create a Git Branch in VS Code
Visual Studio Code provides a robust, built-in graphical interface that makes version control management seamless. This article explains how to quickly create a new Git branch directly within the VS Code interface using three different methods, as well as how to publish your new branch to a remote repository.
Method 1: Using the Status Bar
The quickest way to create a new Git branch is by using the VS Code status bar located at the bottom of the window.
- Look at the bottom-left corner of the VS Code interface to find the
current Git branch name (e.g.,
mainormaster). - Click on the branch name.
- A dropdown menu will appear at the top of the screen. Select + Create new branch… (or + Create new branch from… if you want to branch from a specific commit or tag).
- Type the name of your new branch and press
Enter.
VS Code will automatically create the branch and switch your workspace to it.
Method 2: Using the Command Palette
If you prefer keyboard shortcuts, you can use the Command Palette to create a branch.
- Open the Command Palette by pressing
Ctrl + Shift + P(Windows/Linux) orCmd + Shift + P(macOS). - Type
Git: Create Branchinto the search bar and select the command from the list. - Type your desired branch name and press
Enter. - If prompted, choose the reference branch you wish to branch off from.
Method 3: Using the Source Control Panel
You can also manage your branches through the dedicated Source Control side menu.
- Click on the Source Control icon in the Activity
Bar on the left side of the screen (or press
Ctrl + Shift + G). - Click on the three horizontal dots (…) at the top of the Source Control panel to open the “Views and More Actions” menu.
- Hover over Branch and click Create Branch… from the submenu.
- Enter your new branch name and press
Enter.
Publishing the New Branch to a Remote Repository
Once you create a branch locally, it does not automatically exist on your remote repository (such as GitHub, GitLab, or Bitbucket). To upload it:
- Look at the status bar at the bottom left. A cloud icon with an arrow or a Publish Branch button will appear next to your new branch name.
- Click Publish Branch.
Alternatively, you can open the Source Control panel and click the blue Publish Branch button. Your local branch is now synced with your remote repository.