This Hands-on Tutorial Explains how to use GitHub Extension as Code Repository with Microsoft Visual Studio. Learn Installation Steps and Creation Of Github Repository:
The teams working on .NET projects usually use Team Foundation Server (TFS) as the main code repository for version control activities. This is an expected way of working. There are no doubts about this as the integration of tools from the same vendor is seamless and works without any issues.
But today GitHub is widely used as a web-based code repository. Teams spread across geographically distributed locations can make use of this repository for their version control activities. So it is a good tool for collaboration among team members.
What You Will Learn:
Why Use GitHub Extension?
Basically, when an organization or teams that have been using GitHub for quite some time and would like to continue leveraging it as far as comfort is concerned with the usage and also without making any additional investments then one would look to use GitHub for any kind of projects.
In the previous articles, we have discussed how TFS can be used to store code and other artifacts. In this article, we will see how a .NET project can be shared with the GitHub repository.
- Microsoft Visual Studio.NET 2015 version
- Access to the GitHub repository
- Git installed locally on the Windows machine. Click here to download Git.
Install GitHub Extension For Visual Studio.NET
Before we share the .NET project to the GitHub repository, it is necessary to install the GitHub extension to Visual Studio.NET IDE.
Click here to download the extension from the Visual Studio Marketplace.
Double click on the extension downloaded and click on Install.
If your Visual Studio.NET IDE is open, then restart once. To check if the extension is installed, launch the IDE and go to Tools-> Extension and Updates section and search for GitHub under the Installed category.
Create A GitHub Repository From Visual Studio.NET
Once the GitHub extension is installed to the Visual Studio .NET IDE, go to the Team Explorer home screen and create a GitHub repository.
Enter the GitHub repository name and credentials. Also, ensure to give a proper local path where the local Git repository will be located with the .NET project.
Click on Create. As shown below figure, the GitHub repository is created and you can now create a new Project or Solution by clicking on the link as shown in the Team Explorer.
GitHub Repository view:
Back in Visual Studio.Net IDE, click on the Create project or Solution link in the Team Explorer. Select the checkbox “Create new Git repository” and click OK.
Note that the location of the local Git repository is automatically selected where the .NET project would be stored.
The project is now created in the appropriate location.
Back in the Visual Studio.Net IDE, click on the Team Explorer-> Changes to commit the changes to the local Git repository.
Enter a comment and click on Commit All. Once committed to the local Git repository, we can Sync the changes to be available to teams in the GitHub repository.
Click on the Sync link to upload the code to the GitHub repository. Check the GitHub repository to ensure the .NET project is available. So, essentially we need to run ‘git push’ to the GitHub repository using the IDE and not through the command line.
Click on the Push link as shown below.
The project is now available in the GitHub repository. Here is the view of the same.
Do a small change to any file and perform Commit.
As you can see that once you have modified the file a RED tick has appeared. You can right-click on the file and select Commit.
The changes are shown in the Team Explorer and you can enter the comment and commit all the changes.
Once the Commit is done you need to Sync and Push the changes to the GitHub repository as a normal practice.
The following image is the view of the GitHub repository after changes have been pushed.
Looking At History Of Changes
Let’s now look at the history which lists all the commits that are done by the team and also view what changes were done in that particular commit. It is very interesting to look at or compare changes with the previous commit. So the ‘git log’ command is equivalent here.
In the Team Explorer, click on the Sync option and select Action ->View History
The history of all commits is shown. The Author, Date, and Comments are displayed.
To see the differences with the previous commit right-click on the latest or the appropriate commit and select View Commit Details.
The details about this commit can be seen in the Team Explorer window along with the file to which the changes were done. Double click on the file and the changes are shown using the inbuilt compare window.
In GIT, tags are usually created when you want to label releasing a new version of your application. Let’s see how to create a tag from Team Explorer since we now have the latest commit details shown. This is equivalent to the ‘git tag’ command. From the previous step click on the option Create Tag.
Enter the TAG name and comment as shown below. Click on Create Tag.
View the history of the file again and you will be able to see the TAG.
Let’s see how to create a local branch in the Git repository. Typically, you would create a branch from the master if there are bug fixes or enhancements to be done and then merge into the master branch.
In the Team Explorer, click on the Branches option.
Right Click on the master branch under the local repository and create a new branch.
This is equivalent to using the “git checkout –b” command. Enter the branch name as bug_fix and click on the button Create Branch.
The branch is now created and listed. The work of bug fixing is now being done on the bug_fix branch. This branch is displayed in BOLD and hence indicates that you are currently working on the bug_fix branch.
Let’s make a change to any file, commit and rebase the changes from the bug_fix branch to the master branch.
To merge changes from bug_fix branch to the master branch in Team Explorer, select the branches option and right-click on the master branch and select Checkout.
Now, right-click on the master branch and select Merge from option.
Select the bug_fix branch as the Merge from the branch and click on Merge.
The changes are now reflected in the master branch. All the changes can be PUSHED to the GitHub repository. Go to Team Explorer->Sync and click on Push.
All changes are now pushed and reflected in the GitHub repository.
Github is a hugely popular and widely used source code repository over the web. In this article, we have seen how Visual Studio.NET 2015 can integrate very well with Git and GitHub.
Thus, Visual Studio.NET 2015 cannot only integrate with Team Foundation Server but if there are teams who have been using GitHub extensively over the years then it can integrate very well. So we have seen some developer-level usage of Git operations from the IDE.
Visual Studio.NET 2017 also has more or less the same procedure to integrate with Git and GitHub.