DEV Community

loading...
Cover image for How to use Git and GitHub inside of VS Code Editor

How to use Git and GitHub inside of VS Code Editor

thefierycoder profile image Rishi Purwar ・4 min read

Hello Everyone,

In today's tutorial, I am going to show you How to use Git and GitHub inside of VS Code Editor.

After reading this blog, you don't need to remember all those git commands.

If you prefer to watch a video tutorial, you can check it out over here.

Basic Setup

First, start by creating a new folder and name it whatever you want, and then open it with VS Code Editor.
Screenshot from 2020-11-28 15-54-37.png
And then create a new file inside this folder like a index.html file or name it whatever you want so that we can make some changes to it and demonstrates to you how git and GitHub work inside the VS Code Editor.

Now add a simple boilerplate inside the index.html file by pressing shift + 1.
Screenshot from 2020-11-28 16-02-05.png

Please make sure you are using the latest version of VS Code Editor(I'm using the version: 1.51.1)

Create a GitHub repository

Let's create a new GitHub repository right inside of VS Code Editor. Now, you don't need to go to the official GitHub site and then create a new repository from there anymore.

First, click on the source control icon on the left sidebar or press
ctrl + shift + g to open source control panel. It should look like this.
Screenshot from 2020-11-28 16-57-14.png
And then click on the Publish to GitHub button.
This will open a dialog box like this.
Screenshot from 2020-11-28 16-58-42.png
and then click on the allow button, this will allow the GitHub extension to sign in using your GitHub account.

After that, a window will open in your browser to authorize your GitHub account, just click on the Continue button and then click on the Authorize button to authorize your GitHub account.
Now your GitHub account is setup inside of VS Code Editor.
Again open the VS Code, you will see a dialog box like this.
Screenshot from 2020-11-28 17-09-53.png
First, enter your project name or leave it to default and then select the repository type. If you want to create a public repository, click on the Publish to GitHub public repository, else click on the Publish to Github private repository.

Now, your Github repository is created, if you want to check it, go to the repository section of your GitHub account.
Now, your source control tab should look like this.

Screenshot from 2020-11-28 17-36-27.png

How to use Git inside of VS Code Editor?

Now, make some changes in the index.html file so that we can learn How to use Git inside of VS Code?
I just added an h1 tag inside the file, now the source control panel shows that changed file under the Changes section.
Screenshot from 2020-11-28 17-50-22.png
The next step is to stage these changes, just click on the plus button to stage the changes and if you want to stage all the changes at once then click on the plus icon that is in line with the Changes title respectively.
Screenshot from 2020-11-28 17-53-10.png
Screenshot from 2020-11-28 17-56-05.png
All the changes are now staged. The next step is to commit these changes.
Enter your commit message inside the input and then click on the tick icon to commit all the changes like this.
Screenshot from 2020-11-28 18-01-39.png
Now, the next step is to push these changes to your GitHub repository.
Click on the three-dot button and then click on the Push, Pull option, and then click on Push. This will push all the changes to the master branch.
You can also create a new branch, click on three dots, and then click on Branch and then click on Create Branch and enter your branch name, this will create a new branch for you. Then push all these changes in the branch.
Now, you pushed the changes, if you want to check it, open this repository in your browser.
Screenshot from 2020-11-28 18-17-08.png
Screenshot from 2020-11-28 18-28-29.png

Congratulations🎉! You successfully pushed your changes to your GitHub repository without opening the command line.

Hopefully, you learned about How to use Git and GitHub inside of VS Code Editor.

Thanks for reading this blog

If you find the blog helpful, feel free to subscribe to our newsletter so whenever our new post goes live, you'll get the notification first.

Do leave your feedback and suggestions as comments.

Check out my youtube channel

Let's connect on Twitter

Thank You

Discussion

pic
Editor guide