Introduction
GitHub is a popular platform for developers to manage the version and code of our day-to-day life. There are several ways to interact with GitHub and create a repository and commit code such as Git, GitHub Desktop, Visual Studio, and many more. However, in this article, we will learn how we can use Visual Studio 2022 to connect with GitHub, create a repository and commit code to GitHub. Most developers feel comfortable and easy to use UI in comparison to commands. So in this write-up, we will use and get familiar with Visual Studio as an alternative to the Github command.
Prerequisites
- Visual Studio 2022
Step 1 - Firstly you need to open the project that you want to add to GitHub in Visual Studio 2022. Open your project as shown below.

Step 2 - Once it is open, click on Add to Source Control as illustrated below.

Then select Git as depicted below.

Step 3 - Then you need to provide your Git and Repository details such as:
- Your GitHub account
- GitHub Owner UserName
- By default Git Repo name may create based on your project name however you can give a repository name according to your need or wish.
- Provide the description of your repository which is optional.
For my case, I had already login into the GitHub account on my machine, so account and owner details were auto-populated on the screen below.

After that, if you want to make your repository public then unselect the Private repository.
Furthermore, if you are using Visual Studio Community Preview 2022 - 17.3.0 Preview 5.0 then you can get more options for your repository setup such as gitignore template, License template, and Readme file as portrayed below.

Step 4 - Create and Push
After that, you click on Create and Push button which will create the repository in your GitHub and pushes the code over there.

Once it is pushed you can see the changes in the Visual Studio itself as depicted below. Here, it has created a master branch and pushed the code to the master branch. Additionally, you can see it has created a local master branch as below.











Join the conversation! Your thoughts help the community grow.