Step By Step Setup Git Version Control With .Net Project And Github

In my previous article, we discussed version control and Git. In this article, we will learn what GitHub is and how to set up a .NET project with Git Version Control system and push to GitHub.
 

What is GitHub?

 
GitHub is an open-source code hosting platform having a version control system. Using GitHub, we can work with the team together on projects from anywhere, anytime. We can host our source code projects in different programming languages and keep track of the changes made by the team using Git.
 
Below are the steps to add your VS project to Git and upload it to GitHub.
 
Step 1
 
Open your project in Visual Studio and check the bottom for 'Add to Source Control'.
 
 
Step 2
 
Select Git as your version control, as displayed on the below screen.
 
 
Step 3
 
It will ask you to save your project solution. Just click on Yes.
 
 
Step 4
 
Now, go to Github.com and click on "Start a project", as shown on the below screen. (Before this, you need to create your GitHub account).
 
 
Step 5
 
Once you start, it will ask you to create a new repository. So here, I am going to give the name 'VersionControlWebApp'. Add some sort of description.
 
Chose Public or Private on the basis of how you want to manage your repository and click the 'Create Repository' button.
 
 
Step 6
 
In the Code section, there is a 'Quick setup' link as shown below screen.
 
 
Step 7
 
Now, from your project, open Team Explorer - Synchronization, go to 'Push to Remote Repository', and paste the URL from GitHub (shown in step 6), and click on 'Publish'.
 
 
Step 8
 
Once you click, it will push your code branch to GitHub.
 
 
Step 9
 
After publishing, just log in to GitHub with your login credentials.
 
 
Step 10
 
Now, from Visual Studio, go to Team Explorer. There, you can see Changes, Branches, Sync, Settings options.
 
 
 
Step 11
 
Git will create a local repo as it's a distributed version control system. Now, open your Solution Explorer. It will show a small lock icon on each file, which means all the changes checked into the version control system.
 
 
Step 12
 
Let's make some changes to any file. Here, I am editing About.aspx file and adding 1 line.
  1. <p>Test Git </p>
Once you start editing, the lock icon is changed into a tickmark icon which means there is pending editing. Once you complete the editing, you have to commit or push the changes to the version control.
 
 
  
Step 13
 
For committing my changes, just right click on the file and click on 'Commit'.
 
 
Step 14
 
It will open the Team Explorer and ask for entering 'Commit message'. That way, all the team members know the changes made by you and collaborate works.
 
You can also select or change the branch where you want to push changes from the 'Branch Section'. Here, I am selecting the default branch 'master'. In the "Changes" section, it will show the list of files you want to commit. 
 
 
Step 15
 
Once you enter the description, click on 'Commit All'. This will commit your changes locally and if you want to synchronize with GitHub, you can then click on 'Sync'.
 
You can see here that your changes are created locally - 'Commit ac65383b created locally. 'Sync' to share your changes on the server'.
 
 
Step 16
 
From the Synchronization tab, you can push the changes by clicking on "Push". It will push the current branch of your changes on GitHub.
 
 
Step 17
 
Once done, it will show the message - 'Successfully pushed to origin/master branch'.
 
 
Step 18
 
Open GitHub and check your "Repositories" section. You can see that the change that you committed has been updated here on GitHub. 
 
 
 
You can see, here, in the code section, the changes we made in About.aspx have been synchronized.
 
 
I hope you like this article. In my next article, we will discuss Changes, Branches, Sync, and Settings options in detail. If you have any queries, please feel free to post in the comments section.