In this article, I will explain how to integrate an ASP.NET MVC project with GitHub. Along with that, I will explain some of the below activities often performed by developers on Git.

Prerequisites to achieve this demo are the following -

Let us understand the difference between GitHub and Git

GitHub - This is a distributed version control and source code management system where we can store our projects. We call these projects Repositories (Repos) in GitHub terminology. From here, we can download projects as well as it provides a repository URL to clone it from Visual Studio.

Git

An open source version control system that does the following -

Let’s dive into the actual concept of how we integrate ASP.NET project with GitHub.

Step 1

First, you have to create your personal account on GitHub. Once you create an account successfully, log in and check it.

Step 2

Switch to Visual Studio, open your project, and go to Team Explorer.

Team Explorer option is available under the View menu in Visual Studio, like below.

ASP.NET MVC Project Integration With Github

If you don’t find these options under the Team Explorer window, that means Git is not installed on your Visual Studio. So, first, let’s get the Git installed by using Nuget. Just go to the Tools menu and under that select Extension and Updates where you have to type GitHub in the search box like below.

ASP.NET MVC Project Integration With Github

On my machine, it is already installed. Now, the Git is ready in your Visual Studio to perform operations.

Step 3

Open your project in Visual Studio and go to Team Explorer where you’ll find the below screen.

ASP.NET MVC Project Integration With Github

At the bottom of this screen, you can find "Add to Source Control" option. Click on this and it will pop the Git option up. Clicking it, the below options will be displayed.

ASP.NET MVC Project Integration With Github

Here, let us go to the second option - "Push to Remote Repository" section. Under this, click on the "Publish Git Repo" button. It will ask you to enter the repo name. I have given here the git URL along with the project name like this - https://github.com/MVCApplication and tried to push the repo but it was denied because first, we have to commit these changes locally.

ASP.NET MVC Project Integration With Github

In order to commit these changes locally, we have to go back to options with the help of home button on top of this window. Just click on the home symbol and it will take you to the below screen.

ASP.NET MVC Project Integration With Github

Now, click on the "Changes" tab and commit your changes. By default, Visual Studio creates a master branch on its own and save these files under that branch.

ASP.NET MVC Project Integration With Github

Click on "Commit All" button. Then, it will save all the files under the master branch.

Step 4

Go back to the home again where you will find the Sync option. Just click on it.

ASP.NET MVC Project Integration With Github

After clicking on Sync option, it will display the below screen where you have to provide the GitHub URL.

Make sure you have created this URL in GitHub before entering here.

ASP.NET MVC Project Integration With Github

Click on the Publish button. It will ask you for the GitHub credentials; just enter them. On the successful publishing of all the files and folders, this project will appear under GitHub in the name of the MVC App.

Now, go to the GitHub and check your code under MVC APP Repo.

ASP.NET MVC Project Integration With Github

As of now, we have created a project from Visual Studio and successfully pushed to the GitHub.

How to clone an existing project from GitHub in Visual Studio