Visual studio git

Visual studio git DEFAULT

Git experience in Visual Studio

  • 11 minutes to read

Git is the default version control experience in Visual Studio. We continue to build out the feature set and iterate on it based on your feedback. For more info about a recent feature update along with a link to survey where you can share your feedback on it, see the Multi-repo support in Visual Studio blog post.

Git is now the default version control experience in Visual Studio 2019. Since version 16.6, we've worked on building out the feature set and iterating on it based on your feedback. In version 16.8, it became the default version control experience for everyone.

Learn more about Git

Git is the most widely used modern version control system, so whether you're a professional developer or if you’re learning how to code, Git can be very useful to you. If you are new to Git, the website is a good place to start. There, you'll find cheat sheets, a popular online book, and Git Basics videos.

How to use Git in Visual Studio

We'll walk you through how to use the new Git experience in Visual Studio, but if you'd like to take a quick tour first, check out the following video:

Video length: 5.27 minutes

There are three ways to start using Git with Visual Studio to be more productive:

  • Open an existing Git repository. If your code is already on your machine, you can open it by using File > Open > Project/Solution (or Folder) and Visual Studio automatically detects if it has an initialized Git repository.
  • Create a new Git repository. If your code is not associated with Git, you can create a new Git repository.
  • Clone an existing Git repository. If the code that you would like to work on is not on your machine, you can clone any existing remote repositories.


Starting with Visual Studio 2019 version 16.8, we include a fully integrated GitHub account experience. You can now add both GitHub and GitHub Enterprise accounts to your keychain. You can add and leverage them just as you do with Microsoft accounts, which means that you'll have an easier time accessing your GitHub resources across Visual Studio. For more information, see the Work with GitHub accounts in Visual Studio page.

Create a new Git repository

If your code is not associated with Git, you can start by creating a new Git repository. To do so, select Git > Create Git Repository from the menu bar. Then, in the Create a Git repository dialog box, enter your information.

The Create a Git Repository dialog box in Visual Studio.

The Create a Git repository dialog box makes it easy to push your new repository to GitHub. By default, your new repository is private, which means that you are the only one who can access it. If you uncheck the box, your repository will be public, which means that anyone on GitHub can view it.


Whether your repository is public or private, it's best to have a remote backup of your code stored securely on GitHub even if you are not working with a team. This also makes your code available to you no matter what computer you're using.

You can choose to create a local-only Git repository by using the Local only option. Or, you can link your local project with an existing empty remote repository on Azure DevOps or any other Git provider by using the Existing Remote option.

Clone an existing Git repository

Visual Studio includes a straightforward clone experience. If you know the URL of the repository that you would like to clone, you can paste the URL in the Repository location section and then choose the disk location you would like Visual Studio to clone to.

The Clone a Git Repository dialog box in Visual Studio.

If you don’t know the repository URL, Visual Studio makes it easy to browse to and then clone your existing GitHub or Azure DevOps repository.

Open an existing local repository

After you’ve cloned a repository or created one, Visual Studio detects the Git repository and adds it to your list of Local Repositories in the Git menu. From here, you can quickly access and switch between your Git repositories.

The Local Repositories option from the Git menu in Visual Studio

View files in Solution Explorer

When you clone a repository or open a local repository, Visual Studio switches you into that Git context by saving and closing any previously open solutions and projects. Solution Explorer loads the folder at the root of the Git repository and scans the directory tree for any View files. These include files such as CMakeLists.txt or those with the .sln file extension.

Visual Studio adjusts its View based on which View file you load in Solution Explorer:

  • If you clone a repository that contains a single .sln file, then Solution Explorer directly loads that solution for you.
  • If Solution Explorer doesn’t detect any .sln files in your repository, then by default it loads Folder View.
  • If your repository has more than one .sln file, then Solution Explorer shows you the list of available Views for you to choose from.

You can toggle between the currently open View and the list of Views by using the Switch Views button in the Solution Explorer toolbar.

Solution Explorer with the Switch Views button selected in Visual Studio.

Git Changes window

Git tracks file changes in your repo as you work, and separates the files in your repo into three categories. These changes are equivalent to what you would see when you enter the command in the command line:

  • Unmodified files: These files haven't changed since your last commit.
  • Modified files: These files have changes since your last commit, but you haven't yet staged them for the next commit.
  • Staged files: These files have changes that will be added to the next commit.

As you do your work, Visual Studio keeps track of the file changes to your project in the Changes section of the Git Changes window.

The Git Changes window in Visual Studio.

When you are ready to stage changes, click the + (plus) button on each file you want to stage, or right-click a file and then select Stage. You can also stage all your modified files with one click by using the stage all + (plus) button at the top of the Changes section.

When you stage a change, Visual Studio creates a Staged Changes section. Only changes in the Staged Changes section are added to the next commit, which you can do by selecting Commit Staged. The equivalent command for this action is . Changes can also be unstaged by clicking the (minus) button. The equivalent command for this action is to unstage a single file or to unstage all the files in a directory.

You can also choose not to stage your modified files by skipping the staging area. In this case, Visual Studio allows you to commit your changes directly without having to stage them. Just enter your commit message and then select Commit All. The equivalent command for this action is .

Visual Studio also makes it easy to commit and sync with one click by using the Commit All and Push and Commit All and Sync shortcuts. When you double-click any file in the Changes and the Staged changes sections, you can see a line-by-line comparison with the unmodified version of the file.

The line-by-line comparison of file versions in Visual Studio


You can associate an Azure DevOps work item with a commit by using the "#" character if you are connected to the Azure DevOps repository. You can connect your Azure DevOps repository through Team Explorer > Manage Connections.

Select an existing branch

Visual Studio displays the current branch in the selector at the top of the Git Changes window.

The current branches that you can view by using the selector at the top of the Git Changes selector in Visual Studio

The current branch is also available in the status bar on the bottom-right corner of the Visual Studio IDE.

The current branches that you can view by using the status bar at the bottom-right corner in the Visual Studio IDE

From both locations, you can switch between existing branches.

Create a new branch

You can also create a new branch. The equivalent command for this action is .

Creating a new branch is as simple as entering the branch name and basing it off an existing branch.

The Create a New Branch dialog box in Visual Studio

You can choose an existing local or remote branch as the base. The Checkout branch checkbox automatically switches you to the newly created branch. The equivalent command for this action is .

Git Repository window

Visual Studio has a new Git Repository window, which is a consolidated view of all the details in your repository, including all of the branches, remotes, and commit histories. You can access this window directly from either Git or View on the menu bar or from the status bar.

Manage branches

When you select Manage Branches from the Git menu, you’ll see the branches tree-view in the Git Repository window. From the left pane, you can use the right-click context menu to checkout branches, create new branches, merge, rebase, cherry-pick, and more. When you click the branch, you can see a preview of its commit history in the right pane.

Incoming and outgoing commits

When you fetch a branch, the Git Changes window has an indicator under the branch drop-down, which displays the number of unpulled commits from the remote branch. This indicator also shows you the number of unpushed local commits.

The Git Changes window that shows the indicator drop-down UI element in Visual Studio

The indicator also functions as a link to take you to the commit history of that branch in the Git Repository window. The top of the history now displays the details of these incoming and outgoing commits. From here, you can also decide to Pull or Push the commits.

The Git Repository window that shows the commit history of a branch in Visual Studio

Commit Details

When you double-click a Commit, Visual Studio opens its details in a separate tool window. From here you can revert the commit, reset the commit, amend the commit message, or create a tag on the commit. When you click a changed file in the commit, Visual Studio opens the side-by-side Diff view of the commit and its parent.

The Commit Details dialog box in Visual Studio

Handle merge conflicts

Conflicts can occur during a merge if two developers modify the same lines in a file and Git doesn’t automatically know which is correct. Git halts the merge and informs you that you are in a conflicted state.

Visual Studio makes it easy to identify and resolve a merge conflict. First, the Git Repository window shows a gold info bar at the top of the window.

The 'Merge completed with conflicts' message in Visual Studio

The Git Changes window also displays a ‘Merge is in progress with conflicts’ message, with the unmerged files in their separate section below it.

The 'Merge in progress with conflicts' message in Visual Studio

But if you have neither of these windows open, and instead you go to the file that has merge conflicts, you won’t have to search for the following text:

Instead, Visual Studio displays a gold info bar on the top of the page that indicates that the opened file has conflicts. Then, you can click the link to open the Merge Editor.

Screenshot of 'File contains merge conflicts' message in Visual Studio

The Merge Editor

The Merge Editor in Visual Studio is a three-way merge tool that displays the incoming changes, your current changes, and the result of the merge. You can use the tool bar at the top level of the Merge Editor to navigate between conflicts and auto-merged differences in the file.

The Merge Editor in Visual Studio

You can also use the toggles to show/hide differences, show/hide word differences, and customize the layout. There are checkboxes on the top of each side that you can use to take all the changes from one side or the other. But to take individual changes, you can click the checkboxes to the left of the conflicting lines on either side. Finally, when you finish resolving the conflicts, you can select the Accept Merge button in the Merge Editor. You then write a commit message and commit the changes to complete the resolution.

Personalize your Git settings

To personalize and customize your Git settings at a repository level as well as at a global level, go to either Git > Settings on the menu bar, or to Tools > Options > Source Control on the menu bar. Then, choose the options you want.

The Options dialog box where you can choose personalization and customization settings in Visual Studio IDE

How to use the full Team Explorer experience in Visual Studio

The new Git experience is the default version control system in Visual Studio 2019 from version 16.8 onwards. However, if you want to turn it off, you can. Go to Tools > Options > Environment > Preview Features and then toggle the New Git user experience checkbox, which will switch you back to Team Explorer for Git.

The Preview Features section of the Options dialog box in Visual Studio

What's next

While the new Git experience is now on by default starting with Visual Studio 2019 version 16.8, we continue to add new features to enhance the experience. If you'd like to check out new updates to the Git experience in a Preview release, you can download and install it from the Visual Studio 2022 Preview page.


If you have a suggestion for us, please let us know! We appreciate the opportunity to engage with you on design decisions via the Developer Community portal.

See also


Working with GitHub in VS Code

Using GitHub with Visual Studio Code lets you share your source code and collaborate with others. GitHub integration is provided through the GitHub Pull Requests and Issues extension.

Install the GitHub Pull Requests and Issues extension

To get started with the GitHub in VS Code, you'll need to create an account and install the GitHub Pull Requests and Issues extension. In this topic, we'll demonstrate how you can use some of your favorite parts of GitHub without leaving VS Code.

If you're new to source control and want to start there, you can learn about VS Code's source control integration.

Getting started with GitHub Pull Requests and Issues

Once you've installed the GitHub Pull Requests and Issues extension, you'll need to sign in. Follow the prompts to authenticate with GitHub in the browser and return to VS Code.

Extension Sign In

If you are not redirected to VS Code, you can add your authorization token manually. In the browser window, you will receive your authorization token. Copy the token, and switch back to VS Code. Select Signing in to in the Status bar, paste the token, and hit Enter.

Setting up a repository

Cloning a repository

You can search for and clone a repository from GitHub using the Git: Clone command in the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)) or by using the Clone Repository button in the Source Control view (available when you have no folder open).

Clone From GitHub

Authenticating with an existing repository

Enabling authentication through GitHub happens when you run any Git action in VS Code that requires GitHub authentication, such as pushing to a repository that you're a member of or cloning a private repository. You don't need to have any special extensions installed for authentication; it is built into VS Code so that you can efficiently manage your repository.

When you do something that requires GitHub authentication, you'll see a prompt to sign in:

Authentication Prompt

Follow the steps to sign into GitHub and return to VS Code. If authenticating with an existing repository doesn't work automatically, you may need to manually provide a personal access token. See Personal Access Token authentication for more information.

Note that there are several ways to authenticate to GitHub, including using your username and password with two-factor authentication (2FA), a personal access token, or an SSH key. See About authentication to GitHub for more information and details about each option.

Note: If you'd like to work on a repository without cloning the contents to your local machine, you can install the GitHub Repositories extension to browse and edit directly on GitHub. You can learn more below in the GitHub Repositories extension section.

Editor integration


When you have a repository open and a user is @-mentioned, you can hover over that username and see a GitHub-style hover.

User Hover

There is a similar hover for #-mentioned issue numbers, full GitHub issue URLs, and repository specified issues.

Issue Hover


User suggestions are triggered by the "@" character and issue suggestions are triggered by the "#" character. Suggestions are available in the editor and in the Source Control view's input box.

User and Issue suggestions

The issues that appear in the suggestion can be configured with the GitHub Issues: Queries () setting. The queries use the GitHub search syntax.

You can also configure which files show these suggestions using the settings GitHub Issues: Ignore Completion Trigger () and GitHub Issues: Ignore User Completion Trigger (). These settings take an array of language identifiers to specify the file types.

Pull requests

From the Pull Requests view you can view, manage, and create pull requests.

Pull Request View

The queries used to display pull requests can be configured with the GitHub Pull Requests: Queries () setting and use the GitHub search syntax.

Creating Pull Requests

You can use the GitHub Pull Requests: Create Pull Request command or use the + button in the Pull Requests view to create a pull request. If you have not already pushed your branch to a remote, the extension will do this for you. You can use the last commit message, the branch name, or write a custom title for the pull request. If your repository has a pull request template, this will automatically be used for the description.

Creating a Pull Request


Pull requests can be reviewed from the Pull Requests view. You can assign reviewers and labels, add comments, approve, close, and merge all from the pull request description.

Review Pull Request

From the description page, you can also easily checkout the pull request locally using the Checkout button. This will add a new Changes in Pull Request view from which you can view diffs of the current changes as well as all commits and the changes within these commits. Files that have been commented on are decorated with a diamond icon. To view the file on disk, you can use the Open File inline action.

Changes in Pull Request

The diff editors from this view use the local file, so file navigation, IntelliSense, and editing work as normal. You can add comments within the editor on these diffs. Both adding single comments and creating a whole review is supported.


Creating issues

Issues can be created from the + button in the Issues view and by using the GitHub Issues: Create Issue from Selection and GitHub Issues: Create Issue from Clipboard commands. They can also be created using a Code Action for "TODO" comments.

Create Issue from TODO

You can configure the trigger for the Code Action using the GitHub Issues: Create Issue Triggers () setting.

The default issue triggers are:

Working on issues

From the Issues view, you can see your issues and work on them. By default, when you start working on an issue, a branch will be created for you. You can configure the name of the branch using the GitHub Issues: Working Issue Branch () setting. The commit message input box in the Source Control view will be populated with a commit message, which can be configured with GitHub Issues: Working Issue Format SCM ().

Work on Issue

If your workflow doesn't involve creating a branch, or if you want to be prompted to enter a branch name every time, you can skip that step by turning off the GitHub Issues: Use Branch For Issues () setting.

GitHub Repositories extension

The GitHub Repositories extension lets you quickly browse, search, edit, and commit to any remote GitHub repository directly from within Visual Studio Code, without needing to clone the repository locally. This can be fast and convenient for many scenarios, where you just need to review source code or make a small change to a file or asset.

GitHub Repositories extension

Opening a repository

Once you have installed the GitHub Repositories extension, you can open a repository with the GitHub Repositories: Open Repository... command from the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)) or by clicking the Remote indicator in the lower left of the Status bar.

Remote indicator in the Status bar

When you run the Open Repository command, you then choose whether to open a repository from GitHub, open a Pull Request from GitHub, or reopen a repository that you had previously connected to.

If you haven't logged into GitHub from VS Code before, you'll be prompted to authenticate with your GitHub account.

GitHub Repository extension open repository dropdown

You can provide the repository URL directly or search GitHub for the repository you want by typing in the text box.

Once you have selected a repository or Pull Request, the VS Code window will reload and you will see the repository contents in the File Explorer. You can then open files (with full syntax highlighting and bracket matching), make edits, and commit changes, just like you would working on a local clone of a repository.

One difference from working with a local repository is that when you commit a change with the GitHub Repository extension, the changes are pushed directly to the remote repository, similar to if you were working in the GitHub web interface.

Another feature of the GitHub Repositories extension is that every time you open a repository or branch, you get the up-to-date sources available from GitHub. You don't need to remember to pull to refresh as you would with a local repository.

Switching branches

You can easily switch between branches by clicking on the branch indicator in the Status bar. One great feature of the GitHub Repositories extension is that you can switch branches without needing to stash uncommitted changes. The extension remembers your changes and reapplies them when you switch branches.

Branch indicator on the Status bar

Remote Explorer

You can quickly reopen remote repositories with the Remote Explorer available on the Activity bar. This view shows you the previously opened repositories and branches.

Remote Explorer view

Create Pull Requests

If your workflow uses Pull Requests, rather than direct commits to a repository, you can create a new PR from the Source Control view. You'll be prompted to provide a title and create a new branch.

Create a Pull Request button in the Source Control view

Once you have created a Pull Request, you can use the GitHub Pull Request and Issues extension to review, edit, and merge your PR as described earlier in this topic.

Virtual file system

Without a repository's files on your local machine, the GitHub Repositories extension creates a virtual file system in memory so you can view file contents and make edits. Using a virtual file system means that some operations and extensions which assume local files are not enabled or have limited functionality. Features such as tasks, debugging, and integrated terminals are not enabled and you can learn about the level of support for the virtual file system via the features are not available link in the Remote indicator hover.

Remote indicator hover with features are not available link

Extension authors can learn more about running in a virtual file system and workspace in the Virtual Workspaces extension author's guide.

Continue Working on...

Sometimes you'll want to switch to working on a repository in a development environment with support for a local file system and full language and development tooling. The GitHub Repositories extension makes it easy for you to clone the repository locally or into a Docker container (if you have Docker and the Microsoft Docker extension installed) with the GitHub Repositories: Continue Working on... command available from the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)) or by clicking on the the Remote indicator in the Status bar.

Continue Working on command in Remote dropdown

If you are using the browser-based editor, the "Continue Working On..." command has the options to open the repository locally or within a cloud-hosted environment in GitHub Codespaces.

Continue Working On from web-based editor


  1. 2001 chevy 1500 radiator
  2. Hades offerings wicca
  3. Microsoft careers entry level
  4. Angle iron corner joints
  5. Town buildings minecraft

Using Version Control in VS Code

Visual Studio Code has integrated source control management (SCM) and includes Git support in-the-box. Many other source control providers are available through extensions on the VS Code Marketplace.

Tip: Click on an extension tile to read the description and reviews in the Marketplace.

SCM Providers

VS Code has support for handling multiple Source Control providers simultaneously. For example, you can open multiple Git repositories alongside your Azure DevOps Server local workspace and seamlessly work across your projects. To turn on the Source Control Providers view, select the overflow menu in the Source Control view (⌃⇧G (Windows, Linux Ctrl+Shift+G)), hover over Views, and make sure that Source Control Repositories is marked with a check. The Source Control Providers view shows the detected providers and repositories, and you can scope the display of your changes by selecting a specific provider.

Source Control Repositories view option in overflow menu

SCM Provider extensions

If you would like to install another SCM provider, you can search on the scm providers extension category in the Extensions view (⇧⌘X (Windows, Linux Ctrl+Shift+X)). Start typing '@ca' and you will see suggestions for extension categories like debuggers and linters. Select to see available SCM providers.

SCM Provider category in the marketplace

Git support

VS Code ships with a Git source control manager (SCM) extension. Most of the source control UI and work flows are common across other SCM extensions, so reading about the general Git support in VS Code will help you understand how to use another provider.

Note: If you are new to Git, the git-scm website is a good place to start, with a popular online book, Getting Started videos and cheat sheets. The VS Code documentation assumes you are already familiar with Git.

Overview of Git

Note: VS Code will leverage your machine's Git installation, so you need to install Git first before you get these features. Make sure you install at least version .

👉 When you commit, be aware that if your username and/or email is not set in your Git configuration, Git will fall back to using information from your local machine. You can find the details in Git commit information.

The Source Control icon in the Activity Bar on the left will always indicate an overview of how many changes you currently have in your repository. Selecting the icon will show you the details of your current repository changes: CHANGES, STAGED CHANGES and MERGE CHANGES.

Clicking each item will show you in detail the textual changes within each file. Note that for unstaged changes, the editor on the right still lets you edit the file: feel free to use it!

You can also find indicators of the status of your repository in the bottom-left corner of VS Code: the current branch, dirty indicators, and the number of incoming and outgoing commits of the current branch. You can checkout any branch in your repository by clicking that status indicator and selecting the Git reference from the list.

Tip: You can open VS Code in a sub-directory of a Git repository. VS Code's Git services will still work as usual, showing all changes within the repository, but file changes outside of the scoped directory are shaded with a tool tip indicating they are located outside the current workspace.


Staging (git add) and unstaging (git reset) can be done via contextual actions in the files or by drag-and-drop.

Stage all changes button

You can type a commit message above the changes and press Ctrl+Enter (macOS: ⌘+Enter) to commit them. If there are any staged changes, only changes will be committed. Otherwise, you'll get a prompt asking you to select what changes you'd like to commit and get the option to change your commit settings.

We've found this to be a great workflow. For example, in the earlier screenshot, only the staged changes to will be included in the commit. A consecutive commit action could commit later changes to , the deletion of , and changes to in a separate commit.

More specific Commit actions can be found in the Views and More Actions menu on the top of the Source Control view.

views and more actions button

Tip: If you commit your change to the wrong branch, undo your commit using the Git: Undo Last Commit command in the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)).

Cloning a repository

If you haven't opened a folder yet, the Source Control view will give you the options to Open Folder from your local machine or Clone Repository.

First run Source Control experience

If you select Clone Repository, you will be asked for the URL of the remote repository (for example on GitHub) and the parent directory under which to put the local repository.

For a GitHub repository, you would find the URL from the GitHub Code dialog.

clone repository dialog

You would then paste that URL into the Git: Clone prompt.

set repository URL

You'll also see the option to Clone from GitHub. Once you authenticate with your GitHub account in VS Code, you'll be able to search through repositories by name, and select any repo to clone it. You can also start the flow to clone a Git repository with the Git: Clone command in the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)). To see a step-by-step walkthrough, check out our Clone repos from VS Code video.

Note: If you'd like to work on a repository without cloning the contents to your local machine, you can install the GitHub Repositories extension to browse and edit directly on GitHub. You can learn more in the GitHub Repositories extension section.

Branches and Tags

You can create and checkout branches directly within VS code through the Git: Create Branch and Git: Checkout to commands in the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)).

If you run Git: Checkout to, you will see a dropdown list containing all of the branches or tags in the current repository. It will also give you the option to create a new branch if you decide that's a better option, or checkout a branch in detached mode.

Git checkout

The Git: Create Branch command lets you quickly create a new branch. Just provide the name of your new branch and VS Code will create the branch and switch to it. If you choose to Create new branch from..., you'll get an extra prompt that allows you to specify which commit the new branch should be pointing to.


Given that your repository is connected to some remote and that your checked out branch has an upstream link to a branch in that remote, VS Code offers you useful actions to push, pull, and sync that branch (the latter will run a pull command followed by a push command). You can find these actions in the Views and More Actions menu, along with the option to add or remove a remote.

VS Code is able to periodically fetch changes from your remotes. This enables VS Code to show how many changes your local repository is ahead or behind the remote. Starting with VS Code 1.19, this feature is disabled by default and you can use the setting to enable it.

Tip: You should set up a credential helper to avoid getting asked for credentials every time VS Code talks to your Git remotes. If you don't do this, you may want to consider disabling automatic fetching via the setting to reduce the number of prompts you get.

Git Status Bar actions

There is a Synchronize Changes action in the Status Bar, next to the branch indicator, when the current checked out branch has an upstream branch configured. Synchronize Changes will pull remote changes down to your local repository and then push local commits to the upstream branch.

git status bar sync

If there is no upstream branch configured and the Git repository has remotes set up, the Publish action is enabled. This will let you publish the current branch to a remote.

git status bar publish

Gutter indicators

If you open a folder that is a Git repository and begin making changes, VS Code will add useful annotations to the gutter and to the overview ruler.

  • A red triangle indicates where lines have been deleted
  • A green bar indicates new added lines
  • A blue bar indicates modified lines

Gutter indicators

Merge conflicts

Git merge

Merge conflicts are recognized by VS Code. Differences are highlighted and there are inline actions to accept either one or both changes. Once the conflicts are resolved, stage the conflicting file so you can commit those changes.

Viewing diffs

Our Git tooling supports viewing of diffs within VS Code.

A File Diff in VS Code

Tip: You can diff any two files by first right clicking on a file in the Explorer or OPEN EDITORS list and selecting Select for Compare and then right-click on the second file to compare with and select Compare with 'file_name_you_chose'. Alternatively from the keyboard hit ⇧⌘P (Windows, Linux Ctrl+Shift+P) and select File: Compare Active File With and you will be presented with a list of recent files.

Diff editor review pane

There is a review pane in the Diff editor that presents changes in a unified patch format. You can navigate between changes with Go to Next Difference (F7) and Go to Previous Difference (⇧F7 (Windows, Linux Shift+F7)). Lines can be navigated with arrow keys and pressing Enter will jump back in the Diff editor and the selected line.


Note: This experience is especially helpful for screen reader users.

Timeline view

The Timeline view, accessible at the bottom of the File Explorer by default, is a unified view for visualizing time-series events (for example, Git commits) for a file.

Timeline view

VS Code's built-in Git support provides the Git commit history of the specified file. Selecting a commit will open a diff view of the changes introduced by that commit. When you right-click on a commit, you'll get options to Copy Commit ID and Copy Commit Message.

Visual Studio Code supports more Git history workflows through extensions available on the VS Code Marketplace.

Tip: Click on an extension tile to read the description and reviews in the Marketplace.

Git output window

You can always peek under the hood to see the Git commands we are using. This is helpful if something strange is happening or if you are just curious. :)

To open the Git output window, run View > Output and select Git from the dropdown list.

Initialize a repository

If your workspace is on your local machine, you can enable Git source control by creating a Git repository with the Initialize Repository command. When VS Code doesn't detect an existing Git repository, the Source Control view will give you the options to Initialize Repository or Publish to GitHub.

Git initialize repository

You can also run the Git: Initialize Repository and Publish to GitHub commands from the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)). Running Initialize Repository will create the necessary Git repository metadata files and show your workspace files as untracked changes ready to be staged. Publish to GitHub will directly publish your workspace folder to a GitHub repository, allowing you to choose between a private and public repositories. Check out our publishing repos video for more information about publishing to GitHub.

VS Code as Git editor

When you launch VS Code from the command line, you can pass the argument to make the launch command wait until you have closed the new VS Code instance. This can be useful when you configure VS Code as your Git external editor so Git will wait until you close the launched VS Code instance.

Here are the steps to do so:

  1. Make sure you can run from the command line and you get help.
    • if you do not see help, please follow these steps:
      • macOS: Select Shell Command: Install 'Code' command in path from the Command Palette.
      • Windows: Make sure you selected Add to PATH during the installation.
      • Linux: Make sure you installed Code via our new .deb or .rpm packages.
  2. From the command line, run

Now you can run and use VS Code as editor for configuring Git.

VS Code as Git diff tool

Add the following to your Git configurations to use VS Code as the diff tool:

This leverages the option you can pass to VS Code to compare two files side by side.

To summarize, here are some examples of where you can use VS Code as the editor:

  • do interactive rebase using VS Code
  • use VS Code for the commit message
  • followed by e for interactive add
  • use VS Code as the diff editor for changes

Working with pull requests

Visual Studio Code also supports pull request workflows through the GitHub Pull Requests and Issues extension available on the VS Code Marketplace. Pull request extensions let you review, comment, and verify source code contributions directly within VS Code.

Next steps

Common questions

To push, pull, and sync you need to have a Git origin set up. You can get the required URL from the repository host. Once you have that URL, you need to add it to the Git settings by running a couple of command-line actions. For example:

My team is using Team Foundation Version Control (TFVC) instead of Git. What should I do?

Use the Azure Repos extension and this will light up TFVC support.

Why do the Pull, Push and Sync actions never finish?

This usually means there is no credential management configured in Git and you're not getting credential prompts for some reason.

You can always set up a credential helper in order to pull and push from a remote server without having VS Code prompt for your credentials each time.

How can I sign in to Git with my Azure DevOps organization that requires multi-factor authentication?

There are now Git credential helpers that assist with multi-factor authentication. You can download these from Git Credential Manager for Mac and Linux and Git Credential Manager for Windows.

I have GitHub Desktop installed on my computer but VS Code ignores it

VS Code only supports the official Git distribution for its Git integration.

I keep getting Git authentication dialogs whenever VS Code is running

VS Code automatically fetches changes from the server in order to present you with a summary of incoming changes. The Git authentication dialog is independent from VS Code itself and is a part of your current Git credential helper.

One way to avoid these prompts is to set up a credential helper that remembers your credentials.

Another option is to disable the auto fetch feature by changing the following setting: .

Can I use SSH Git authentication with VS Code?

Yes, though VS Code works most easily with SSH keys without a passphrase. If you have an SSH key with a passphrase, you'll need to launch VS Code from a Git Bash prompt to inherit its SSH environment.



The Simplest Thing Possible: Git and Visual Studio

We've always been able to host our Visual Studio-based solution source code under Git. The problem was, unlike Team Foundation Sever (TFS), Git suffered from a lack of integration into the Visual Studio IDE. Today, that lack of integration is a thing of the past! Recently, Microsoft made Git a first class citizen in TFS. Today, we can choose either TFS or Git for our source code control (SCC) provider on our team projects. To make things work with Git, Visual Studio 2013, as part of its install, also installs Git. Does this mean you have to use TFS or Visual Studio Online to take advantage of Git in Visual Studio? The answer is no. In this article, I'm going to show you how to make Git come alive in Visual Studio - using only what Visual Studio gives you in the box.

What If You Don't Have Git Installed?

In the event you don't have Git installed, navigate to Just follow the instructions and accept the defaults. Figure 1 illustrates the git-scm download page and a command prompt window. If, at the command prompt, you type git and usage guidance and a command list is echoed back, you are good to go!

Figure 1: The git-scm windows download page and the command prompt to verify the git install

New to Git?

The remainder of this article assumes you have at least a working knowledge of Git. If you don't, that's OK. The good news is that with Visual Studio, you don't have to understand, out of the gate, how Git works, although at some point, you'll want to be acquainted with how Git works and its command line syntax. One of the best resources to learn Git is the free e-book called “Pro Git,” by Scott Chacon, illustrated in Figure 2.

Figure       2      : Pro Git by Scott Chacon is a free e-book available on the site.

Git Version Control versus TFS Version Control

The primary difference between Git and TFS Version Control (VC) is their respective type. Where TFS is centralized, Git is distributed. In a distributed VC system, each client has its own local repository that is synced with one or more remote repositories. Each local repository, among other things, is capable of branching, merging, and commits. In a centralized VC system, there's only one repository that's hosted on a server. It's only with that centralized server where branch, merging, and commit activities occur. In a centralized model, developers must have consistent connectivity to the central repository to get the advantages of VC. In a distributed model, developers only need connectivity when they need to sync their changes. Recognizing the value of distributed VC and Git's popularity, Microsoft baked Git into TFS. Now, when you create a TFS or Visual Studio Online Team Project, you pick your version control provider: Git or TFS.

The Git support in Visual Studio is not some customized version of Git. Rather, the support is for Git itself. In addition, there is support for common remote Git hosters like GitHub and BitBucket. If your project happens to be in a directory that has an initialized git repository, the Git features in Visual Studio, as you'll see in a moment, “Light up.” Of course, to get the benefit of associating work items with source code commits, you need to use TFS or Visual Studio Online.

Getting Started: Creating a Remote Repository on GitHub

Figures 3 and 4 illustrate the new GitHub repository.

Figure       3      : When you create a repository in GitHub, you can specify a number of options.
Figure       4      : Main GitHub page for the repository

With the GitHub repository created, the next step is to clone the repository to a local Git repository. To do that, you'll use Visual Studio and specifically, the NuGet Package Manager Console.

The Git support in Visual Studio is not some customized version of Git. Rather, the support is for Git itself.

Cloning a GitHub Repository with PowerShell in Visual Studio

PowerShell is a powerful tool; Visual Studio ships with a PowerShell Command Window. You know it as the NuGet Package Manager Console. Figure 5 illustrates that PowerShell has no issues with the Git command and, as you can see, cloning a remote repository is quite simple.

Figure       5      : Executing the Git Clone Command from the NuGet Package Manager PowerShell Console

Figure 6 confirms, via the File Explorer, the cloned repository.

Figure       6      : The cloned repository as shown in the File Explorer. Note that the context menu recognizing the directory has a Git repository.

In the next step, The Visual Studio Team Explorer will be connected to the local repository.

Connecting Visual Studio to Git

Figure 7 illustrates the New Project dialog. Note that the local Git repository is located in the directory.

Figure       7      : The new project will be saved to the new Git repository's home directory.

You aren't quite done. You have to tell Visual Studio to add the current solution to source control. Figure 8 illustrates how to invoke this menu option.

Figure       8      : To add a solution to Git source control, the Add to Source Control menu option has to be selected.

Once the project has been added to source control, the Solution Explorer reflects that status. Figure 9 illustrates the Solution Explorer.

Figure       9      : When the Add to Source Control menu option is selected, Visual Studio detects the existing Git repository.

If you elect to add a project to source code control, you are prompted to choose between TFS and Git. Figure 10 illustrates how this works. The Output Window confirms the creation of a new local Git repository (assuming that is the option you chose). In this sequence, you have to associate your local Git repository to your remote repository. To this, you issue the following command:

Figure       10      : Once the Git option is selected, a new Git repository is created. From there, it's easy to specify the remote repository in the Package Manager PowerShell Console.

With the Visual Studio Project under Git Source Control, it's time to turn your attention to the Team Explorer.

Working with Git and the Team Explorer

Figure 11 illustrates several things. First, Visual Studio is not connected to any TFS. Once upon a time, in order to use the Team Explorer, there needed to be an active connection to TFS. This new native support for Git changes all of that. TFS is a great environment, but it's not for everyone. Why should native and integrated support for source code control have a dependency on TFS?

Figure       11      : Once a solution is placed under local Git source code control, the Team Explorer is available to use. You no longer need to be connected to TFS to use the Team Explorer.

From here, if you're familiar with how to use the Team Explorer to commit changes to a source code repository, you already know what to do. Figure 12 illustrates the basic work flow. First, you select the Changes Button in the Team Explorer. Once you provide a commit message, you can commit these changes to your local repository. There are three options:

  • Commit: Pending changes are sent into the local repository only.
  • Commit and Push: The same as Commit with the added step of sending the changes to the remote Git repository (hosted in GitHub for this example).
  • Commit and Sync: The same as Commit and Push with the added step of bringing any changes in the remote Git repository into the local Git repository.

For this example, you'll just Commit and then sync your changes in a separate step.

Figure 12: Committing source code changes in the Team Explorer works just like committing changes to a TFS Source Code Repository.

Figure 13 illustrates the results of the first commit. It really is that easy. Everything that was done with the Team Explorer could have been done with Git commands via the command prompt, Git Bash, or as previously demonstrated, the NuGet Package Manager PowerShell Console.

Figure       13      : Using commit history as an example, inside Visual Studio, you can elect to use the Team Explorer, a command prompt, or some combination when interacting with Git.

It's important to note that while you can accomplish most things with Git in the Team Explorer, there are some functions that require you to use the command line. A good example of this is the git stash command. There is no facility in the Team Explorer to stash current work without committing that work before switching to another branch.

Now that you have committed your changes, the next thing you need to do is push those changes to the remote server. That step is illustrated in Figure 14.

Figure 14: From the Team Explorer, it is very easy to sync the local and remote Git repositories.

That's all there is to syncing with the remote Git epository. The local repository knows about the remote repository because the local repository was created by cloning the remote repository. If, on the other hand, you create the local repository first, you have to invoke the git remote add command.

About Branching and Merging

Branching and merging is very easy to accomplish within the Team Explorer. To demonstrate, let's create a branch called development. Figure 15 illustrates that work flow. Note that the Checkout branch checkbox is checked. When you check out a branch, it makes that branch the currently selected branch. You're always on a branch. When you first create a repository, there's one branch called master. This is the root branch, or what is often referred to as the trunk. The idea is that over time, the trunk will sprout branches like a tree. Eventually, activity in those branches is merged back to the trunk over time. Before you can switch branches, you either have to commit or stash your work. Stashing work places your work in a temporary holding place without the need to commit to the current branch.

Figure       15      : From the Team Explorer, it's very easy to create local branches and publish those branches to the remote repository.

Figure 16 illustrates the new branch in the remote repository hosted in GitHub. Now, that branch is available for other developers to use. When they sync their local repositories, they will be able to work in that branch.

Figure       16      : When a branch is published, it becomes available in the remote repository.

Today, regardless of whether you're using Team Foundation Server or Visual Studio Online, you can leverage Team Explorer for managing and interacting with Git source code control.

Merging is just as easy. The following list enumerates one possible workflow.

  1. Checkout the branch you wish to work in. You can either use the git checkout command or you can select the branch in the Team Explorer.
  2. Make your changes.
  3. Sync your local repository with the remote repository, making sure that your local copy of the master is up to date.
  4. Commit your changes in the branch.
  5. Merge your changes from the branch (source) to the master (target). You can also merge from one branch to another branch. Or, you can merge from master to a branch.
  6. If there are no merge conflicts, sync changes with remote repository.

Figure 17 illustrates where and how to initiate a merge in the Team Explorer. As with everything else, you have the option of initiating these operations via commands in a command prompt.

Figure       17      : Merging, like branching, can be initiated in the Team Explorer.


As you can see, Git is now a first-class citizen in Visual Studio. You've always been able to have your Visual Studio-based projects controlled in Git. That process wasn't integrated, and you had to rely on an external command prompt or some other Git user interface. Today, regardless of whether you're using Team Foundation Server or Visual Studio Online, you can leverage Team Explorer for managing and interacting with Git source code control. Prior to these latest changes, in order to use the Team Explorer, you had to also connect with and use a TFS Team Project. Today, your remote Git repository can be hosted anywhere. In this article, GitHub was used, but another service, such as BitBucket, could have been used as well.

In spite of all the graphical user interface goodness that Visual Studio gives us, there are times when you need to use a command prompt to interact with Git. You may also be a developer who's more at ease with the command prompt but have missed that integration in Visual Studio. With the NuGet Package Manager PowerShell Console, you have a fully functional Git command window that is fully integrated in Visual Studio.

With Visual Studio, you don't need to worry about having to be a Git command-line ninja. Instead, you can leverage Team Explorer for most of your functions. Over time, in order to get the most out of Git, you'll want to be acquainted with the raw commands. The good news is that you can ease into that knowledge while remaining productive with the Team Explorer.

In addition to the free git e-book available at, I've published a number of videos that teach you how to integrate Git with Visual Studio and Visual Studio Online. For more on that, navigate to If you are new to Wintellect, enter the promo code PETERSEN-14 for two free weeks of access.

If you are interested in TFS but don't have the licensing dollars to shell out, you're in luck. Check out Visual Studio Online at You can get a free instance for up to five users.

Have additional technical questions?

Get help from the experts at CODE Magazine - sign up for our free hour of consulting!

Contact CODE Consulting at [email protected]


Studio git visual

Using Git with Visual Studio 2019: The Ultimate Guide

We’ve written extensively in previous articles about the non-negotiable importance of learning source control to become a software engineer and the most popular tool to accomplish it: Git. Git’s command line has, for lack of a better way of describing it, evolved into somewhat of a conflicting journey. If you’re looking for a better experience to manage your Git repositories, this guide introduces you to using Git with Visual Studio 2019.

Many developers prefer having the ability to manage repositories inline with the development environment to reduce having to context switch between applications. The downside to this is that you lose the flexibility and customization of the command line. We suggest you start with our extensive guide to Git and follow that up with this guide so that you know how things are working under the hood.

And hey, if things start going haywire, you’ll know how to use the backup method!

Install Git & Learn Git

Git works natively on Windows, Mac, and Linux. When using Windows, you’ll most likely be using the tools included in the Git for Windows initiative (Git BASH, Git GUI, and Git Shell Integration). Even though Git is completely cross platform, Visual Studio 2019 only works on Windows.

To get started, go to the download Git page or directly to the download link for Windows since you’re stuck on Windows with Visual Studio.

Don’t know how to use Git? Take a look at our Getting Started with Git guide so that you’re set up for success and ready to contribute to projects with confidence.

Go to top

Install Visual Studio 2019

Microsoft sometimes has weird ways of naming their products (Azure DevOps, we’re looking at you). There was a period of time when everything was named with the Visual Studio prefix. That said, don’t confuse Visual Studio 2019 with Visual Studio Code. This guide only uses Visual Studio 2019.

Let’s get started.

Download Visual Studio 2019 Community Edition (free). Read our pricing guide for more detailed comparisons between editions. We suggest the Community Edition because you won’t need any of the features offered by the pricier (and they can be pricey) tiers.

Browser window showing where to click to download Visual Studio 2019 community edition.

Microsoft recently overhauled the installation process. It’s much, much better than it used to be, so let’s all take a moment of silence to appreciate that.

Anyway, you’re not going to need the thousands of options that are available to you during the initial installation process. This guide only uses the “.NET Core cross-platform development” group and its required dependencies. Feel free to opt in to anything else you think looks interesting but be aware that you will have to download everything. Some of these options can increase the download size by 5+ GB.

Visual Studio installer UI showing to install only .NET Core tooling.

Let the installer do its thing. Sit back, relax, and wait for the magic. While it’s downloading, you can check out our article on 5 Essential Visual Studio Extensions. Used properly, extensions have the potential to boost your productivity and development efficiency.

Go to top

Create New Git Repository

You’ve got Visual Studio, and you’re ready to roll. If you want to know how the Visual Studio Git UI is interacting with Git under the hood, read our introduction to Git to learn the basics of the command line.

Visual Studio tries to be helpful on launch, but sometimes jumps the gun. In this case, we don’t want to create any projects to start. Instead, we want to create a new repository, but that’s hidden behind the tiny link in the bottom right: “Continue without code.” Click it.

Visual Studio UI showing where to click to skip project creation and create a Git repo first.

To create a new repository:

  1. Click File –> New –> Repository…
  2. The Team Explorer opens on the right
  3. Pick the folder that you want to create the repository in

This is equivalent to running from the command line.

Visual Studio UI showing where to create a new Git repository.

Go to top

Create Project In New Git Repository

The repository is ready to go, but it’s empty. Confirm that the repository now shows in the “Local Git Repositories” section of the Team Explorer.

Initiate the Project Creation Wizard by clicking File –> New –> Project. Yes, there are keyboard shortcuts to do this, but they’re not very convenient. You can remap them, but really how often are you going to be creating new projects to justify a handy shortcut?

Visual Studio UI showing where to create a new project.

There are definitely a lot of project templates to sift through. If you selected more installation options in the first steps of this guide, you’ll be absolutely swimming in them.

Search for “console” to filter down to just console applications. Select “C# Console App (.NET Core)” to create a new console application based on whatever version of .NET Core SDK was installed with Visual Studio 2019. Note that there are templates for other languages (VB and F#) that aren’t relevant to this tutorial.

Click Next.

Visual Studio UI showing where to create a new .NET Core console application.

Enter your project name, select the folder location in which you initialized the Git repository from previous steps. If you get this wrong, you won’t be able to follow along with the rest of the guide.

Click create, and you’re good to go. Your solution, project file, and template classes will be created and placed in your repository folders.

Visual Studio UI showing how to make a new project with caveats.

Go to top

Commit New Project to Git

Visual Studio has a “Team Explorer” docked sidebar (you can drag it to move it around) which enables you to manage your local Git repository and attached remotes.

Change the Team Explorer section drop down to “Changes” so that you can view changes on your active branch (which is the master branch at the moment).

Even though your project has been added to your local repository folder, you haven’t yet committed those changes. Files that Git recognizes as new are not tracked by default and require you to explicitly add the files to be tracked. If you don’t see any changes listed here, go back to the project creation step and make sure that you created the project in the same folder as the Git repository.

Visual Studio UI showing where to see Git repository code changes.

The Changes window in the Team Explorer tab breaks down changes in two ways: “Changes” and “Staged Changes”.

  • Changes is a list of pending file changes that you haven’t acted on. That is, you haven’t run on those files to stage them for a commit.
  • Staged Changes is a list of files that have been added to Git’s staged tracking list to be committed. In this step, Visual Studio’s repository creation wizard has automatically staged and files based on built in templates.

Specifically, the file was sourced from the GitHub gitignore repository.

Visual Studio UI showing where to see staged and pending Git changes.

Click the to stage all changes. In this case, staging everything is fine, but in the real world, you might want to pick and choose exactly which changes to stage. It’s common for developers to make local changes specifically for debugging or testing purposes without the intention of committing those to the repository.

Do yourself and your team a favor by always double checking your changes prior to staging and definitely prior to commitment.

Visual Studuio UI showing how to stage changes.

The Team Explorer UI will update with all changes in the Staged Changes section. Confirm that these are as you expect prior to commitment.

If anything looks wrong at this step, you can Unstage by right clicking the file and selecting “Unstage”.

Visual Studio UI showing how to confirm changes are ready to be committed.

Good commits have good commit messages. Good commit messages aren’t too short and nor too long. That’s vague, but the point is that you should be descriptive enough for those who will come after you but without requiring the reader to struggle to the end.

You have three options here:

  • Commit Staged to commit staged changes to the local repository
  • Commit Staged and Push to commit staged changes to the local repository and push to a remote repository (like GitHub or Bitbucket)
  • Commit Staged and Sync to commit staged changes to the local repository, pull changes from a remote repository, and then push your changes to that remote repository

We only care about the first one for this guide because we have no remote repositories setup.

Visual Studio UI showing how to commit to local Git repository.

At this point the project is committed to Git and enshrined in the history forever. Let’s work on incremental changes now.

Go to top

Commit a Change to Git

Any time you add or change a file to the tracked repository, the Visual Studio Team Explorer will automatically detect and display the changes in the Changes tab.

Add a line to the file and watch as the change displays automatically.

Visual Studio UI showing how to make a change and have Git recognize it.

Before you commit stage and commit changes, always check to make sure the changes are what you expected. Long development sessions can leave behind unwanted comments and code that you intended to remove prior to commitment.

Right click the file or folder that changed and click “Compare with Unmodified…” to see what changes are pending to be staged or committed.

The previously chosen option will launch the Visual Studio Diff Viewer, which displays changes between the (left, unmodified state of your branch) and the current state (right, pending changes that haven’t yet been committed).

Red lines on the left indicate the previous state. Green lines on the right indicate the current state.

Always confirm that these changes are exactly as you expect.

If everything is as expected, just like before, click the to stage the changes. Enter the commit message (a good one). Click “Commit Staged” to commit to the local repository.

Visual Studio UI showing how to stage and commit a change to local Git repository.

We encourage all developers to commit early and commit often. Reduce your risk and keep your coworkers sane by maintaining small and frequent changes.

Go to top

Create and Commit to a Local Branch

As we previously wrote about in 5 Essential Things Every Programmer Should Know, branching is critical to your success, your team’s success, and ultimately your project’s success.

Without the ability to create independent branches of code, team members would be conflicting with each other every time a developer made a commit. Since we also advocate for committing early and committing often, such conflicts would be an immediate deal breaker.

Change the Team Explorer section drop down to “Branches” so that you can view all branches in the local repository.

Visual Studio UI showing how to switch to Git "branches" view.

The only branch in a new repository is the default branch known as . Until now, all changes have been committed against that branch.

Right click the branch, click “New Local Branch From…” to begin creating a branch based on the current state of .

Visual Studio UI showing how to create a new local branch.

The new branch UI will display in the Team Explorer. Name the new branch, confirm that you are branching from , and select to checkout the branch so that you don’t have to do that manually after creation. It’s just an option for convenience.

Branch naming is a hot topic and can invoke a lot of opinions. One common naming convention is found in the Gitflow Workflow.

  • feature/ prefix indicates that work committed to the branch represents changes for a new feature. Example: .
  • bugfix/ prefix indicates that work committed to the branch represents changes for a bug fix. Example: .
  • hotfix/ prefix indicates the branch will have an escalated release path because of critical fixes included on it. Example: .
  • release/ prefix indicates a standard release branch which includes tested and ready-to-go features an fixes. Example: .

Ultimately the naming convention is up to you and your team to decide. Whatever works best for your flow is fine. Just make sure the names make sense.

Visual Studio UI showing how to name and create a branch.

Confirm the branch was created and that it is now the active branch (indicated by bold lettering) in the Branches tab of Team Explorer.

If you didn’t click to checkout the branch upon creation, you’ll have to double-click the branch now to switch to it.

Visual Studio UI showing how to confirm new branch creation.

After confirming that the new branch is the active branch, it’s time to add some changes and commit to that branch.

Just like in the previous sections, add a new line to . You should see changes automatically detected and displayed in the Changes tab.

Again, just like before, use your new skills to confirm your changes, stage those changes, enter a good commit message, and then commit the changes to the new branch.

Visual Studio UI showing how to make changes and commit on a branch.

There is no difference in the process of committing to a separate branch. In fact, is considered a branch as well, so the process is exactly the same.

But how do we get our changes back to the branch so that other coworkers can use our changes? Surely we don’t want our changes isolated in a separate branch forever.

Go to top

Merge a Branch Into Master

Branches are nearly useless if kept in isolation forever. Team members would be working on features that never get merged together. The application would then have its code split across a ton of different branches!

Branching in Git works by merging from a source branch into an active branch. For example, if you want to merge changes from a feature branch into the branch, you need to checkout the branch to make it active and then select the feature branch as the source. You are essentially “pulling” changes from a branch into the active branch.

In the Branches tab of Team Explorer, you can double-click the branch or right click then “Checkout” to switch to that branch.

Visual Studio UI showing how to checkout a branch.

Confirm that you successfully checked out the branch. Right click it, then select “Merge From…” to begin the process of merging into the active branch.

Visual Studio UI showing how to merge from a branch.

The Team Explorer UI will update to allow you to select the source branch (merge from) and confirm the destination branch (master).

Select the feature branch created in the previous sections as the branch to merge from. Check to commit changes after merging. If you don’t check this, you will need to take an extra step to manually commit the merged changes. This is just a convenience option.

Finally, click Merge to complete the operation.

Visual Studio UI showing how to select a branch to merge.

If the merge operation was clean (no conflicts, see below), then you’re good to go. You should still be on the branch and see the changes from your feature branch available to you.

Good practice dictates a process of branching early, branching often, committing early, and committing often. All of that combined reduces your risk, keeps your changes isolated from massive conflicts, allows you to test in isolation, and keeps your product delivery cycles unblocked.

Go to top

Resolve Merge Conflicts

This is the part about source control that everyone hates. But it doesn’t have to be insurmountable. Good branching and commit cadence can reduce the size of conflicts.

When multiple people are working on the same lines of the same files in different branches, at some point there will be a collision. That’s because there are sometimes new features and fixes that may overlap with code that was changed by someone else on a different branch.

So what if you add another statement to on one branch, and your coworker also adds a statement on the same line in on a different branch? There will be a conflict.

When this happens (it’s a matter of when, not if), the Branches tab in Team Explorer will popup a warning indicating that the merge cannot be automatically completed because manual intervention is required to resolve a conflict.

Either Abort the merge (not recommended unless you have no idea how to resolve the issue) or click the Conflicts link to display which files are in conflict.

In the Conflicts list, select a file in conflict to display resolution options.

  • Merge button will open the diff editor to manually resolve conflicting lines
  • Diff link will show differences between the files for visibility
  • Take Source will ignore changes on the active branch and overwrite with changes on the incoming source branch
  • Keep Target will ignore changes on the source branch and overwrite with changes on the active branch

Click Merge to begin the manual merge resolution editor.

Visual Studio UI showing how to confirm merge conflicts.
Visual Studio UI showing how to choose a file to resolve merge conflicts.

In the diff editor, you will see three windows.

  • Source (left) viewer will show the changes made on the incoming source branch
  • Target (right) viewer will show the changes made on the target active branch
  • Result (bottom) viewer shows what the merge will look like depending on the resolution decisions

Select the highlighted-in-red conflicting line that you want to resolve. At the top toolbar, click the “Take Left” or “Take Right” icons to indicate which change you want to take.

This step might require you to discuss changes with a coworker if you are merging someone else’s changes into your branch. Depending on the decided upon resolution, you may even end up taking both changes!

Visual Studio UI showing how to decide and take left or right merge changes.

Check the bottom window to see what the resulting file will look like after you decided which changes to take.

If everything looks OK, click “Accept Merge” in the upper left to confirm that the file merge conflict has been resolved. If you skip this step, the merge operation on the file will still be marked as pending and in conflict.

Visual Studio UI showing how to confirm and accept merge resolution.

If you selected to commit after merge in the previous step, then the merge conflict has been resolved and automatically committed. Otherwise you’ll need to go back and complete the merge operation as appropriate.

Go to top

View File Commit History

You will inevitably need to check the history of a file to determine who changed what or where something went wrong. It’s extremely common to need to refer to previous commits for the purposes of debugging or reverting.

Right clicking any file in the Solution Explorer shows an option to View History.

Visual Studio UI showing how to view file history.

In the file history viewer, you’ll see a list of commits, authors, dates, and commit messages. Use this window to give yourself some context about how the file got to its current state.

Visual Studio UI showing how to view commit history for file.

Right clicking a commit will reveal options:

  • Open to view what the file looked like on that commit
  • View Commit Details to view what the full context of the commit was beyond just this file
  • Compare with Previous… displays a diff between the commit and the immediately preceding commit
  • Blame (Annotate) will show a breakdown of the file per line to show who last altered that line

Click to Compare with Previous to open the diff viewer.

Visual Studio UI showing how to compare commit changes from history.

At this point, you’ll see the diff viewer popup to reveal differences between two commits. The viewer looks the same as it did previously in the “Compare to Unmodified” steps earlier in this article.

Go to top

Set Up Remote Repositories

While it’s great that you’re now maintaining your code in Git repositories, the problem is that they’re only local. By taking advantage of remote repository services like GitHub, Bitbucket, and Azure DevOps, you can maintain backups and allow others to contribute.

Connect to GitHub

We are strong advocates of using GitHub to build up a public portfolio of your work to support your job and team search adventures.

To connect your repository to GitHub, change the Team Explorer window to “Sync”. For some reason, Visual Studio will display this tab as “Push”. Click “Publish to GitHub” to initiate the login process using your GitHub credentials. Don’t have any? Don’t worry, GitHub is free!

Visual Studio UI showing how to initiate publishing to a remote repository

As stated just now, login or sign up to GitHub.

Visual Studio UI showing how to sign in to GitHub

If the login process is successful, the UI will update to include your account profile and username. Plus, it automatically fills in the repository name based on whatever you named it locally. You don’t have to have the same name, but it helps for clarity to be consistent.

Enter a name and a description then click “Publish”. We don’t suggest making this a private repository as discussed in our guide to building a portfolio on GitHub.

Visual Studio UI showing how to connect to a remote repository

And finally, if the remote repository creation was successful, you should see a success message. You can double confirm by checking the Branches tab in Team Explorer to see that a new branch in the remote repository was created and available now in your local repository.

Visual Studio UI showing how to confirm remote branch

Connect to Other Remotes

The process is largely the same for non-GitHub repositories. Instead of clicking “Publish to GitHub” in the first step, click “Publish to Git repo” at the bottom.

When prompted, enter the remote URL (usually ends with a extension) to push your changes to. You may be prompted for credentials if pushing to a secured system.

Visual Studio UI showing how to initiate publishing to a remote repository

Go to top

Push & Pull Changes

What good is connecting your repositories if you don’t know how to push your changes and pull your team’s changes? Fortunately, Visual Studio makes that really easy.

Change to the “Sync” tab in Team Explorer to see the incoming and outgoing commits sections.

Incoming commits are those that you are expected to pull in to your local repository to reconcile against other contributor’s changes. Click the “Pull” link to initiate pulling those changes.

Outgoing commits are those that you have committed locally but don’t yet exist on the equivalent remote branch. If you have commits that meet these criteria, you’ll see a list of them in this section. Confirm and click “Push” to push those changes to the remote repository.

Visual Studio UI showing how to push and pull changes

Quick Note: if you see an error complaining about not having a matching remote branch when trying to push, that usually means you don’t have any commits in your local repository to push. This is because Git doesn’t create the branch until you’ve committed at least one time so there are no branches against which Visual Studio can match and push.

Go to top

Clone Remote Repository

Sometimes you don’t have a local repository to push and instead want to pull an existing repository down locally to begin contributing to it. That’s when you have to clone.

Unfortunately, Visual Studio doesn’t make finding this option very intuitive. Click the little green plug at the top of the Team Explorer window to switch to the Connections tab. We have no idea why this tab is hidden from the normal tab selector drop down.

Under the Local Git Repositories section, click the Clone link to start the process. Enter the URL of the remote repository and where you’d like the clone to end up on your local disk. By default, the clone process will also clone submodules. Don’t uncheck that unless you explicitly know you don’t need it.

Finally, click the Clone button to download and clone the repository to a matching local repository. This process will create the linked remote automatically for you, and you won’t need to go through the previous process of connecting.

Visual Studio UI showing how to clone a remote repository

Go to top

Learn the new Git User experience in Visual Studio 2019

See his eyes, darkened with desire. Missing me, bitch. Yes, I say with my lips. I miss you too, girl, and on your shameless tongue, - and he falls with his lips to mine, gently touches. Them, runs his tongue outlining the contour of my mouth, and from this I feel a heavy dark desire spreading its tentacles inside my belly all over my body, touching them and the tips toes, and the back of the head, and palms.

Now discussing:

Those who wish will be able to observe it while standing both along the perimeter of the courtyard and from the wide porch. For this performance, a Chinese fireworks master was specially engaged from some fair. The guests dispersed around the courtyard, in the middle of it a platform. Was erected on which the master conjured over his weapons. Finally, he lowered long wicks from different sides along the edges of the platform and, waiting for the signal, began to.

31349 31350 31351 31352 31353