How to Connect a Visual Studio Project to GitHub

Introduction

 
In this article, you will learn how to create a new project and connect to Github for the first time. We'll also look at push pull code from Github.
 

Create your application

 
Step 1
 
Open Visual Studio and select File >> Create a new project.

How To Connect Visual Studio Project To GitHub 
 
The ”Create a new project” window will pop up. Select “ASP.NET Core Web Application” and click “Next”.
 
How To Connect Visual Studio Project To GitHub 
 
After clicking on this, the “next” window will pop up. Select “Web Application” and click on “Create”, as shown below:

How To Connect Visual Studio Project To GitHub
 
Step 2

Once your project is ready, open Solution Explorer and check to see if your project code is ready. Then, “build” the project and click on “IIS Express” to run the project.

How To Connect Visual Studio Project To GitHub
 
After running the project, you can see your project in the browser along with localhost.
 
Step 3
 
This step is most important in order to connect to Github.

After running & checking your project, click on File and you will see 'Add to Source Control'. Now click on 'Add to Source Control'. If you don't see the Add to Source Control in the File tab, then you can find “Add to Source Control” in Visual Studio at the bottom, as shown below.
 
How To Connect Visual Studio Project To GitHub

After clicking on ‘Add to source Control,’ open ‘Team Explorer’ (which you will find in the View tab on top of Visual Studio). Click on the Home tab in ‘Team Explorer’. There you can see your project name, as shown below.

How To Connect Visual Studio Project To GitHub
 
Now click on the “Sync” tab and it will open a new tab. There, you will see “Publish to GitHub” & “Push to Azure DevOps Services” & “Push to Remote Repository”. Now click on “Publish to GitHub”. You can also see your project name and branch in the bottom of Visual Studio.
 
How To Connect Visual Studio Project To GitHub

After clicking on “Publish to GitHub” it will open in another window.
 
Now configure your Github account with Visual Studio. If you don’t have an account with Github, then create a new account https://github.com/ .
 
After configuration, you will see your username on Github and the project name as a Repository name. If you want to add a description, then you can optionally add one. If you want to make your repository private, then click on the checkbox, or otherwise leave it. Now click on the publish button.
 
 
After clicking on publish, it’ll take a little bit of time. After finishing, it will show you the message, “Repository Created Successfully”. Again, click on sync and click on pull. It will show “Repository is already up to date. No changes to pull”.
 
How To Connect Visual Studio Project To GitHub
 
Now you can see your project in GitHub. Open your GitHub account and check all the code uploaded with the project name Repository.
 
How To Connect Visual Studio Project To GitHub
 
Step 4

Now open Visual Studio and change some code. Click on the Home tab in “Team Explorer”. Now click on the Changes tab.
 
How To Connect Visual Studio Project To GitHub
 
After clicking on the Changes tab, it will open in another window. Here, you can see the changes file.
 
How To Connect Visual Studio Project To GitHub
 
Now give a commit message. The changes you are going to commit to should be specific. Then click on the “Commit All” button. Next, click on the Sync link, which is shown in the commit message.

It will show another window. Click on the push link which is in outgoing Commits. After clicking on push, it’ll take time to update the Github Repository.
 
How To Connect Visual Studio Project To GitHub
 
After pushing the code in Github repo, you can see your changes with the commit message.
 
How To Connect Visual Studio Project To GitHub
That's it. I hope that you found this article helpful. Please let me know via comments and likes!


Recommended Free Ebook
Similar Articles