Visual Studio 2019 | Visual Studio 2017 | Visual Studio 2015
The first commit in a new Git repo is the start of the main branch. As you work in the main branch, you make commits to record your work in that branch. Branching in Git occurs when you create a new line of development that diverges from a prior branch. You might choose to create a new branch to develop and test a new feature before adding it to your main branch. The recommended Git workflow is to use a new branch for every feature or bugfix. When you switch between branches, Git almost instantly switches the version of your repo files to match the branch you selected. Your commits are always saved to the current branch, and are isolated from commits in other branches.
Branch names can't contain ASCII control characters, such as spaces, tildes, and colons. It's common practice to use lowercase characters and to separate words with a hyphen. Forward slashes can be used to group branches. Branch name length shouldn't exceed 250 ASCII characters. To avoid ambiguity between branch names and commit hashes, don't use branch names that consist of 40 hexadecimal characters. For more information on branch naming, see git-check-ref-format and Git cross-platform compatibility.
View your repo's branches by selecting Branches while viewing your repo on the web.
Select New branch in the upper-right corner of the page.
In the Create a branch dialog box, enter a name for your new branch, select a branch to base the work off of, and associate any work items.
Select Create branch.
Tip
After you've created a remote branch, you can fetch it into your local Git repo. At the command prompt, run: git fetch git switch <remote branch name>
Visual Studio 2019 version 16.8 and later versions provides a Git version control experience while maintaining the Team Explorer Git user interface. To use Team Explorer, uncheck Tools > Options > Preview Features > New Git user experience from the menu bar. You can use Git features from either interface interchangeably. Below, we provide a side-by-side comparison of how to create a branch.
Visual Studio Git
From the Git menu on the menu bar, choose New Branch to open the Create a new branch window.
In the Create a new branch window, enter a descriptive branch name to let others know what work the branch contains. By default, Visual Studio creates your new branch from the current branch. The Checkout branch checkbox automatically switches you to the newly created branch. Select Create.
Visual Studio Team Explorer
In Team Explorer, select the Home button and choose Branches.
Right-click the default branch, often named main, and then choose New Local Branch From
Enter a descriptive branch name to let others know what work the branch contains. Select Create Branch.
Visual Studio 2015 & 2017
Open up Team Explorer and go to the Branches view.
Right-click the parent branch (usually main) to base your changes and choose New Local Branch From....
Supply a branch name in the required field and select Create Branch. Visual Studio automatically performs a checkout to the newly created branch.
To create a new branch, use the git branch command. This command doesn't switch your current branch to the new branch.
git branch <new branch name>
To switch to a branch, use the git checkout command.
git checkout <existing branch name>
To create and switch to a branch in one command, use the git checkout command with the -b flag.
git checkout -b <existing branch name>
Tip
You can also use git switch <existing branch name> to switch to a new branch. Or, to create and switch to a new branch in one command, use git switch -c <new branch name>.