A Complete Git and GitHub Workflow Using VS Code Only
Published: 2020-12-02 11:07:24

I recently discovered that I could integrate Github into my Visual Studio Code. This means that I can create pull requests, create issues, clone repositories, collaborate with others, etc., without leaving VS Code. I was excited and decided to write about it. In this article, we’ll go over how to complete some of the things we do on Github right in VS Code.

We will cover the following:

1. [Setup](#setup) 
2. [Clone a project](#clone-a-project) 
3. [Stage and commit](#stage-and-commit)
7. [Create a new branch](#create-a-new-branch)
8. [Stash changes](#stash-changes)
3. [Push changes](#push-changes) 
6. [View commit timeline](#view-commit-timeline)
10. [Create pull requests](#create-pull-requests) 
4. [Pull from a remote repository](#pull-from-a-remote-repository) 
9. [Add a remote repository](#add-a-remote-repository) 
11. [Publish a new project](#publish-a-new-project) 

## Prerequisites

I’m assuming you have some experience with Git, GitHub, and VSCode. You can still follow along if you do not have any experience, but you’ll need the following:

- [A GitHub account](https://github.com/join).
- [Visual Studio Code](https://code.visualstudio.com/download) installed in your machine.
- [Git](https://git-scm.com/) installed in your machine.


> VS Code has a Git integration as one of its source control options, but for it to work, [Git](https://git-scm.com/) needs to be installed on your machine.

## Setup

Integrating Github with VS Code is done through [Github Pull Requests and Issues](https://marketplace.visualstudio.com/items?itemName=GitHub.vscode-pull-request-github) extension. 
Open VS Code and click on the extensions panel. Search for GitHub Pull Requests and Issues. Next, install the extension and authenticate with GitHub.

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1605878892147_image.png)


After installing the extension, click on the account icon on the activity bar to log in to your GitHub account.

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1605880295225_image.png)


Click on the “Sign in to use GitHub Pull Request and Issues link.

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1605881020275_image.png)


VS Code will navigate you to the browser. Click on the  **Continue**  button to give VS Code access to GitHub.

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1605881508014_image.png)

You will see a screen asking if you want to authorize GitHub for VS Code. Click the Authorize GitHub button. 
![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1605881754006_image.png)

Confirm your GitHub password to continue. You will see a success screen with your authorization token as displayed below. 

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606742691049_image.png)

If you are not redirected to VS Code, copy the token manually and switch back to VS Code. Click on “Signing in to github.com” in the Git status bar at the bottom of the screen, paste the token and press the Enter or return key on your keyboard. You may need to reload your VS Code window for the extension to start working.
![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1605930727685_image.png)


## Clone a project

We will clone by clicking on the **Clone Repository**  button in the source control view. Click on the “Clone from GitHub” link as seen below.

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1605932725325_image.png)

You will see a dropdown asking if you want to enable authentication through GitHub. Click the **Allow** button. VS Code may redirect you to your browser, where you need to authorize GitHub for VS Code like we did when setting up; otherwise, you should see a dropdown with a list of the repositories you have on your GitHub account. You can search for and clone any repository on GitHub.
![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1605943824556_image.png)



Select where you want the repository to be stored. If you already have a folder, select it and click the **Select Repository Location** button. You can also open your desired folder on VS Code and then clone into it.

Once it finishes, you will see a prompt on VS Code asking if you want to open your cloned file in the current window or a new window. 


![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1605944675582_image.png)

If you want to clone a repository belonging to someone else, you can click on the **Clone Repository** button in the source control view. Paste the URL of the repository in the search bar.

See the example below.
![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606815924751_image.png)

## Stage and commit 

While working or making changes to files, your source control tab should reflect the number of files you have made changes. 
Click on the source control tab to see a list of all the files you’ve made changes to. Click on any file or hover over it until you see a plus sign appear. Click on the plus sign, and VS Code will add the file to your staging environment.  

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606391433345_image.png)


If you have many files and want to stage all of them, instead of clicking the plus sign one after the other, you can click on the **More Actions menu (...).** From the dropdown, select **Changes** and select **Stage All Changes.**

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606392016142_image.png)

To commit the staged files, add your commit message and click the checkmark. This will save your changes to your local repository.
![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606392212484_image.png)

## Create a new branch

1. Click the current branch name from the git status bar.
![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1605956492013_image.png)

2. Select “Create new branch” from the dropdown - this will create a branch from the current branch you are working on.
3. Type in the name of the new branch and hit Enter. VS Code will automatically switch to the new branch.

### Create a branch from an already existing branch 
![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606368403647_image.png)

From the dropdown, select “Create new branch from…” - This will create a new branch from some other branch in the current git repository.

## Stash Changes

If you are working on something and do not want to commit the changes yet, probably because you haven’t finished working on them, you need to stash them. Stashing them will move your modified files into a stack of unfinished changes and leave you with a clean working directory. You can restore the stashed files at any time, even on a different branch.


1. Click on the source control tab.
2. Click on the More Actions menu (...) on the changes view.

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606383563682_image.png)

3. Select Stash from the dropdown.
4. Select Stash again.

VS Code will prompt you to enter a stash message to identify the stash and hit the Enter key. You will have a clean working directory now. 

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606384242083_image.png)


To restore stashed changes, click on the **More Actions menu (...)**, hover over **Stash** and select **Apply Stash.**  

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606384791864_image.png)


You will see a dropdown of your stashed changes. In the screenshot above, we have just one. Go ahead and select the stash you want to apply. This will apply the changes and still leave the entry in the stash.
If you want to restore the stashed changes and delete the entry from the list of stashes, instead of selecting **Apply Stash,** select **Pop Stash** from the dropdown.

## Push changes

To push changes in your local repository to a remote repository on GitHub that you own or are a contributor to:

1. Click on the source control tab
2. Click on the More Actions menu **(...)**
3. From the dropdown, select **Push, Pull.**
4. From the dropdown, select **Push to…**

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606394558581_image.png)


You will be given an option of any configured remote repository.

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606394891819_image.png)


Select the repository, and that’s it. If you want to check if the changes were pushed to GitHub, you can go to the GitHub repository and confirm.

## View commit timeline

You can view the Git commit history of every file in the timeline view. The timeline view will, by default, update to show the timeline for whatever file you currently have open.  

To view the timeline for a specific file in your project:

1. Click on the file.
2. Scroll down to the bottom of the File Explorer and click on Timeline.
![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606623624550_image.png)


For every commit in the Timeline, you’ll see the commit title, the name of the person who made the commit, and when that commit was made.
If you click on any commit, it’ll show you a diff view of the changes made by that commit.

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606623967432_image.png)

## Create pull requests

To create a pull request after the changes in the local repository has been pushed to the remote repository on GitHub, you’ll need to do the following:

1. Click on the GitHub Pull Request tab to open the Pull Requests view.
2. Click on the + button.
3. Choose the target branch for the pull request and hit the  Enter key.

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606665480672_image.png)


If your branch hasn’t been published yet, the extension will do it for you. After completing the first three steps above, VS Code will prompt you to pick a name for the branch and hit the Enter key.

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606665917171_image.png)


After publishing the branch, you’ll need to select a title for the pull request. From the menu, as seen in the screenshot below, you can use the latest commit message, the branch name, or specify a custom title.

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606671319548_image.png)


Once you select the pull request title, your pull request will be created. 
You can add a code reviewer and label if you want.

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606711594261_image.png)

## Pull from a remote repository

To pull from a remote branch into your local repository, you need to do the following:

1. Click on the source control tab.
2. Click on the More Actions menu **(...).**
3. From the dropdown, select **Pull, Push.**
4. From the dropdown, select **Pull** if you have  ****only one remote connected or **Pull from** if you have multiple remotes to pick from.

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606714379690_image.png)


If you select **Pull from**, you’ll need to select the remote you want to pull from. As seen below, I have only my default remote, which is origin.

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606714552152_image.png)


You’ll also need to select a branch to pull from.

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606714877062_image.png)


Once you select your branch, that’s it!!

## Add a remote repository

To add a remote repository to your project:

1. Click on the source control menu.
2. Click on the More Actions menu **(...).**
3. From the dropdown, select **Remote** and click on **Add Remote…**

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606724116850_image.png)


You can either provide the repository URL or add a remote from GitHub.
Click on Add remote from GitHub. You can search for a repository name or select one from the dropdown as seen below.

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606724314487_image.png)


Next, you’ll have to provide a remote name you can reference easily and press  Enter.

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606724776182_image.png)


To add remote from URL, you can paste the repository URL in the search bar and follow the same steps.

## Publish a new project

1. Open your project on VS Code.
2. Click on the source control menu.
3. Click on Publish to GitHub button - This option is only available if git has not been initialized in the project.
4. You’ll have to decide if you want to make it a public or private repository
![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606720160712_image.png)

5. Select the file you want to include in the first commit and click the **Ok**   button.
![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606720383582_image.png)


I created just the `index.html` file for this illustration, as seen below.

![](https://paper-attachments.dropbox.com/s_DEFC8E4E34C657FCAAEA3AB05A1BBEA0BF3ED9898BE389E85B79000C12D080F9_1606720839630_image.png)


The repository has been successfully published to Github.

Yayyy!! You made it to the end of this post, and I hope that you found new tips or tricks to enhance your productivity regardless of your experience level. I bet you’d agree with me that this is the coolest thing since Jollof rice. If you haven’t had Jollof rice, we need to fix that!! Thank you for reading!