Visual Studio Team Services : Hosting Your First Project Using Git From Visual Studio

Visual Studio Team Services is the new name for Visual Studio Online which was a collection of all the online services of Visual Studio. But the name "Visual Studio Online" was very confusing, many people thought that it's a web version of Visual Studio. So they decided to rename it as "Visual Studio Team Services" bringing along some new features with it too. You can read more about setting up Visual Studio Team Services Account, its features and pricing from here.

In this post, I am going to show you how to host a repository in Visual Studio Team Services, store and collaborate code from Visual Studio.

Creating Project

Let's start by creating a new project from the Team Services Dashboard by clicking on the New link.

Give a name and description for the project in the modal window, select Git for version control and process template as Agile and click on the Create New Project button.

Adding Code

Clicking on the Navigate to project will show a modal dialog window, where you will have two options. One is for managing the work and other is for adding code. Let's add code to our repository by clicking on the Add Code button.

You will be redirected to the home page of your repository, where it will list the git commands needed for cloning the repository in the local machine and for pushing a local repository to the hosted account. Additonal options for integrating with popular IDE's like IntelliJ, Android Studio, Eclipse are also available in the page

What I am going to do is to create a repository in the local machine and will push it to the hosted account after adding the project from Visual Studio. You need to have Git for Windows client installed your machine to make this approach work. You can read about the installation process of Git Client in one of my earlier post.

Creating Project in Visual Studio and Pushing into Online Repository

Let's create a sample console application in Visual Studio from File -> New Project. Make sure that you select the Create New Git Repository option while creating it as shown in the below screenshot

Now, go to the folder in the PowerShell command window and list the contents by executing the dir command. As you can see from the below screenshot that, VS has already created the .gitattributes and .gitignore files, since we have chosen to create a new git repository while creating the project. 

You can verify whether the creation of local repository is successful or not from the Team Explorer window as shown below.

To publish the local repository to your online account execute the following commands

git remote add origin https://techrepository.visualstudio.com/DefaultCollection/_git/Sample

git push -u origin --all

This will add your repository and pushes all the files to the hosted repository as shown below.

Code Explorer in Visual Studio Team Services

You can view the code and the check in history in Team Services under the Code Menu.

In the Explorer tab, it will list all the checked in files as shown below. You may recollect that while creating our online repository, it was empty and now it has the solution which we pushed from the command prompt and the complete history can be viewed from History tab

        

Instead of using the command prompt, you can use the Team Explorer window in Visual Studio to publish it to the online repository. I will be blogging about in another upcoming post, till then happy coding/


No Comments

Add a Comment