Clone and use a GitHub repository in Visual Studio Code

Learn the steps to clone a public repository from GitHub to your local computer using Visual Studio Code.

Clone repository

To get started, download the sample project using the following steps:

  1. Open the command palette with the key combination of Ctrl + Shift + P.

  2. At the command palette prompt, enter gitcl, select the Git: Clone command, and press Enter.

    gitcl command in the Visual Studio Code command palette prompt

  3. When prompted for the Repository URL, select clone from GitHub, then press Enter.

  4. If you are asked to sign into GitHub, complete the sign-in process.

  5. Enter azure-samples/js-e2e-express-server in the Repository URL field.

  6. Select (or create) the local directory into which you want to clone the project.

  7. When you receive the notification asking if you want to open the cloned repository, select Open.

Initialize new repository

If you don't have a GitHub repository yet, but would like to start your project locally, initialize your folder with git.

  1. Select source control from the activity bar, or use the key combination of Ctrl + Shift + G.
  2. Select Initialize repository.

Create a branch for changes

  1. Open the command palette with the key combination of Ctrl + Shift + P.

  2. Search for git branch and select Git: Create Branch.

    Search for `git branch` and select `Git: Create Branch`.

  3. Enter a new branch name. The branch name is visible in the status bar.

    The branch name is visible in the status bar.

Commit changes locally

Once you have made changes on your branch, commit the changes.

  1. Open the command palette with the key combination of Ctrl + Shift + P.

  2. In the command palette, filter with Git then select Commit.

  3. Enter your commit message, then press Enter.

    Adding the yarn.lock file to Git

Push a local branch to GitHub

  1. Open the command palette with the key combination of Ctrl + Shift + P.
  2. In the command palette, filter with Git then select Push.
  3. If you have multiple upstream remotes, select the remote then press Enter.

View Git output

You can view the Git commands run when you use the Source control extension. This helps debug when a command fails.

  1. Select the Source Control icon from the activity bar.

  2. Select the ellipsis (...) then select Show Git Output.

    Visual Studio Code source control, with the Show Git Output selection highlighted.

Visual Studio Code tools to work with Git and GitHub

Working in Visual Studio Code with a repository uses separate tools.

Icon Information Access from
Git commands in command palette F1
Icon for Source control. Source control extension Activity bar
Icon for GitHub PRs and Issues GitHub Pull Requests and Issues extension Activity bar
GitHub Repositories extension You can quickly and easily open a GitHub repository either by searching for GitHub Repositories: Open Repository... from the Command Palette, F1, or by choosing Open GitHub Repository... from the remote indicator (the green button in the lower left corner of the status bar).

Next steps