How to Use Visual Studio for GitHub Repository
Tags: github, devops, visualstudio, azuredevops
Published: 2022-09-22 05:58:24

## 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.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/byjdo1qsq70ix8x1fxqx.jpg)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gbiguz8as9zzi5qacdy2.jpg)

Then select Git as depicted below.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i92gwaslohcfztorkjfz.jpg)

**Step 3** - Then you need to provide your Git and Repository details such as:

1. Your GitHub account
2. GitHub Owner UserName
3. 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.
4. 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.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fp1iesq5feq5lo713f8l.jpg)

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 or a later version of Visual Studio then you can get more options for your repository setup such as gitignore template, License template, and Readme file as portrayed below.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c1iljy0g93a9db89kyuu.jpg)

**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.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ed81oi7a90ogn5lurpz.jpg)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bmbbjtypjh15ptz1c2th.jpg)

If you click on the remote tab in the above screen, then you can see it has created a master branch in origin as well.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ftuq1jsfyj59webzhm7.jpg)

Additionally, you can open your GitHub account and check the newly created repository. It should appear as shown below.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dpb2xigqn35clirgrrzp.jpg)

## Utilizing VS 2022 for GitHub for updated files
In this section, we will learn how we can use git in Visual Studio 2022 for committing and pushing the code to the GitHub repository.

Once you change the code you can see the lately changed files in the option Git Changes tab as illustrated below.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v9461rohfzvcpmr3fwbl.jpg)

**Step 1 - Commit code locally**

Provide the message in the enter a message field in the above screen and then click on Commit All.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/60inqz9kr9cf2xaey1fq.jpg)

It commits the changes locally in your machine which you can see on the screen as portrayed below. Here, you have 1 outgoing commit.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o6cs82olnhu0rgbb3k35.jpg)

**Step 2** - Fetch changes of remote Origin to your local

If you are only one person working on the repo, then you can click on the push option. If there are new changes in the GitHub repository(origin) then you need to first fetch the remote/origin and then can push the code.

The fetch option is depicted below.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r0mec4691z9bgvcnhj1i.jpg)

**Step 3** - Push changes

The pushing code is illustrated below.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hldks6da8lb0yr8i9m25.jpg)

Additionally, once you fetch the code you can directly click the sync option which firstly pulls the code and then pushes it to the remote origin.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p208fohnaw7wrw0xbd6t.jpg)

Once you pushed the code, you can see the changes in GitHub which should as like below.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t8perbvdtbcfn427kkw9.jpg)

Moreover, you can explore some more options by clicking on the… option as depicted below to get familiar with other available git options in Visual Studio.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rzsm43kuj09m07xukv7h.jpg)

## Conclusion
Hence, in this article, we created a GitHub repository and pushed the code to the newly created repository in GitHub using Visual Studio 2022. In addition to this, we learned to push the changes to GitHub using Visual Studio. I hope this article will give you an easy way to manage your code in GitHub using the Visual Studio interface instead of the Git command or Git Hub desktop in an effective way.

**Reference**

- [Rijsat.com](https://rijsat.com/2022/08/01/using-visual-studio-2022-for-github/)