Muokkaa

Jaa


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.

Open your remote repository

Open your remote repository on your local computer.

  1. Install the Remote repository extension
  2. Select the remote indicator in the lower left of Visual Studio Code.
  3. Follow the prompts.

Visual Studio Code uses Git authentication provided by the operating system (such as macOS KeyChain or Windows Credential manager) with any git functionality. Output is visible in Command Palette > Git: Show Git Output.

Open your local repository

If you have an existing repository on your local computer and want to open it in Visual Studio Code, just open the folder. Visual Studio Code recognizes the .git subfolder and display the relevant information.

  1. Select Ctrl + K + O.
  2. Select folder.

Initialize new repository

Use the following procedure to create a local source code repository with git.

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

  2. Select Initialize repository.

    Screenshot of Visual Studio showing the Initialize repository button.

Once the repo is initialized, create the repository on GitHub. Then add that repository as a remote to your local project from the Command palette: search for Git: Add remote.

Create a branch for changes

Create a new branch to capture changes and isolate from the main or default branch.

  1. Select source control from the activity bar.
  2. Select ellipsis (...) next to Source Control.
  3. Select Branch -> Create Branch.

Commit changes locally

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

  1. Select source control from the activity bar.

  2. Enter your commit message, then select Commit.

    Adding the yarn.lock file to Git

Push a local branch to GitHub

  1. Select the Source Control icon from the activity bar.
  2. Select Publish Branch. If the repository doesn't exist on GitHub, it creates the repository for you.

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