Visual Studio for Teams of C++ Developers

In this blog post we will dive into how Visual Studio supports teams of C and C++ developers. We’ll begin by creating a small C++ program and placing it in a Git repository in Visual Studio Team Services. Next we’ll see how to commit and push updates and get updates from others. Finally, we will work with GitHub repos using the GitHub extension for Visual Studio.

Adding an Existing C++ Project to Git in Visual Studio Team Services

In this example, you will create a small sample application and use Visual Studio to create a Git repository in Visual Studio Team Services. If you have an existing project, you can use it instead.

To get started you’ll need an account on Visual Studio Team Services. Sign up for a free Visual Studio Team Services account. You can use a personal, work or school account. During the process, a new default project may be created but will not be used in this example.

  1. Download the sample project from and unzip it into a suitable working directory. You can also use one of your own C++ projects; the steps will be the same.
  2. Start Visual Studio 2017 and load the CalculatingWithUnknowns solution. Expand the Source Files node in Solution Explorer to see the solution files:
    Visual Studio Solution Explorer showing project C++ source files
  3. The blue status bar at the bottom of the Visual Studio window is where you perform Git-related tasks. Create a new local Git repo for your project by selecting Add to Source Control in the status bar and then selecting Git from the . This will create a new repo in the folder the solution is in and commit your code into that repo.
  4. You can select items in the status bar to quickly navigate between Git tasks in Team Explorer.
    Status bar showing four different Git tasks

    1. Up-arrow with two shows the number of unpublished commits in your local branch. Selecting this will open the Sync view in Team Explorer.
    2. Pencil with 0 shows the number of uncommitted file changes. Selecting this will open the Changes view in Team Explorer.
    3. Current repo is CalculatingWithUnknowns  shows the current Git repo. Selecting this will open the Connect view in Team Explorer.
    4. Current Git branch is master shows your current Git branch. Selecting this displays a branch picker to quickly switch between Git branches or create new branches.
  5. In the Sync view in Team Explorer, select the Publish Git Repo button under Publish to Visual Studio Team Services.
    Sync view in Team Explorer with Publish Git Repo button highlighted in red
  6. Verify your email and select your account in the Account Url drop down. Enter your repository name (or accept the default, in this case CalculatingWithUnknowns) and select Publish Repository. Your code is now in a Team Services repo. You can view your code on the web by selecting See it on the web.

As you write your code, your changes are automatically tracked by Visual Studio. Continue to the next section if you want to learn how to commit and track changes to code, push your changes and sync and get changes from other team members. You can also configure your C++ project for continuous integration (CI) with Visual Studio Team Services.

Team Explorer Home dialog highlighting the example, CalculatingWithUnknowns C++ project, was pushed and you can see it on the web.

Commit and Push Updates and Get Updates from Others

Code change is inevitable. Fortunately, Visual Studio 2017 makes it easy to connect to repositories like Git hosted in Visual Studio Team Services or elsewhere and make changes and get updates from other developers on your team.

These examples use the same project you configured in the previous section. To commit and push updates:

  1. Make changes to your project. You can modify code, change settings, edit text files or change other files associated with the project and stored in the repository – Visual Studio will automatically track changes. You can view changes by right-clicking on a file in Solution Explorer then clicking View History, Compare with Unmodified, and/or Blame (Annotate).

C++ source file differences in CalculatingWithUnknowns.cpp.

  1. Commit changes to your local Git repository by selecting the pending changes icon from the status bar.

Status bar showing one pending change in the C++ project

  1. On the Changes view in Team Explorer, add a message describing your update and commit your changes.

Team Explore Changes dialog with a branch comment and the Commit All button highlighted

  1. Select the unpublished changes status bar icon or the Sync view in Team Explorer. Select Push to update your code in Team Services/TFS.

To sync your local repo with changes from your team as they make updates:

  1. From the Sync view in Team Explorer, fetch the commits that your team has made. Double-click a commit to view its file changes.
  2. Select Sync to merge the fetched commits into your local repo and then push any unpublished changes to Team Services.
  3. The changes from your team are now in your local repo and visible in Visual Studio.

Work with GitHub repos using the GitHub Extension for Visual Studio

The GitHub Extension for Visual Studio is the easiest way to connect your GitHub repositories in Visual Studio. With the GitHub Extension, you can clone repos in one click, create repositories and clone it in Visual Studio in one step, publish local work to GitHub, create and view pull requests in Visual Studio, create gists and more.

In this section, we walk through installation, connecting to GitHub and cloning a repo.

  1. Install the GitHub Extension for Visual Studio. If you already have Visual Studio installed without the extension, you can install the GitHub Extension it from the Visual Studio GitHub site. You can also select it as part of the Visual Studio installation process. To install (or modify) with Visual Studio 2017, run the installer and click Individual components and then click GitHub extension for Visual Studio under Code tools, then proceed with other selections and installation (or modification):

Individual components in the installer with GitHub extension for Visual Studio selected

  1. On the Connect view of Team Explorer, expand the GitHub connection and select Sign In. Provide your GitHub credentials to complete sign in.

Team Explorer Connect dialog with GitHub options including sign-in

  1. Click Clone to bring up a dialog that shows all the repositories you can access. If you want to clone one, select it and then click Clone.
  2. To create a new repo, click Create and provide information about the repository. You can choose among several Git ignore preferences and licenses and choose whether your repo is public or private. If you have a private account, you will be restricted to private repositories.

Create a GitHub Repository dialog

  1. To publish an existing project on your machine, click on the Sync tab in the Team Explorer window to get to the Publish to GitHub

To learn more about the extension, visit the GitHub Extension for Visual Studio page.