Sdílet prostřednictvím


Manage branches

TFS 2018

Manage the work in your team's Git repo from the Branches view on the web. Customize the view to track the branches you care most about so you can stay on top of changes made by your team.

View your repo's branches by selecting Branches while viewing your repo on the web.

Access the branches view from your Git repo in Team Explorer

Organize your branches

The default Mine tab on the branches page shows branches you've created, pushed changes to, or set as a favorite, along with the default branch for the repo, such as main. The All tab lists all branches in the repo, and the Stale tab lists branches in the repo that haven't had any commits in three months or longer.

My branches

If you don't see the branch you're looking for and you think it might have been deleted, see Restore a deleted branch.

Filter the listed branches in any of the branch views by entering a specific name or pattern in the Search all branches box in the upper right.

Search and filter branches viewed using the search all branches field
If your team uses a forward slash separator in your branch names, you'll see a collapsible tree view for those branches.

Tip

Using a naming convention for your branches is highly recommended. For suggestions on how to name your branches, see Adopt a Git branching strategy.

Add favorite branches

Add branches from the All view to the Mine view by selecting the star icon to favorite the branch. Mark multiple branches as favorites by selecting the star icon on the tree view next to a folder on the tree. Remove favorites by toggling the star off or by selecting the ... to the right of the star to open the branch context menu, then selecting Remove from my favorites.

Set favorites in your branches to show them in the Mine view

Review updates to your branches

Each branch name has the name of the last contributor to the branch and a link to the latest commit on the branch. Select the date or time of the last commit to review the updates to the branch. The branch view also shows the number of commits the branch is ahead of and behind the branch labeled Compare. Use this information to quickly check how far a branch has diverged from another.

If the branch has a pull request open, you can see its pull request ID. Select the pull request to open it up so you can review the details.

See how far a branch is ahead of and behind the compare branch

Change the compare branch

The ahead and behind numbers listed for each branch are in comparison with the branch currently labeled Compare on the Branches page. Update your compare branch to see how far ahead or behind your branches shown on the page are to another branch in your repo:

  1. Select the ... next to the branch you want to set as the baseline for comparison.
  2. Select Set as compare branch.

The Compare label will move to this branch and the other branches on the page will have the number of commits ahead/behind updated to reflect the new comparison.

View branch history

Review the files in a branch or history by selecting the ... icon next to the branch name and choosing View files or View history. View files opens up the Files view on the web so you can browse the files based on the most recent commit on the branch. View history shows each commit in the branch history. Select a commit from this history to see the file changes made in that commit.

Access the view files and review history from the branches context menu

Change your default branch

You can use a branch other than main for new changes or change your main line of development in your repo. To change the default branch name for new repositories, see All repositories settings and policies.

To change your repo's default branch for merging new pull requests, you need at least two branches. If there's only one branch, it's already the default. You must create a second branch to change the default.

Note

Changing the default branch requires you to have Edit policies permission. For more information, see Set Git repository permissions.

  1. Select the settings button in your project to open the project administration page.

    Open the administrative area of the web portal for your project

  2. Select Version Control.

  3. Select your Git repository. Your branches are displayed under your repo.

  4. Select the ... next to the branch you want to set as default, then select Set as default branch.

    Set a default branch for a Git repo

  5. Once you've set the new default branch, you may delete the previous one if you want.

There are other aspects you should consider before making this change. Learn about them in this article on changing your default branch.