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.
- Install the Remote repository extension
- Select the remote indicator in the lower left of Visual Studio Code.
- 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.
Connect to Custom GitHub Domains
By default, Visual Studio Code assumes your repositories are hosted on github.com
. If you need to connect to a repository on a different domain (for example, an enterprise GitHub like github.<company_name>.com
), you'll need to configure your Git path accordingly.
To update the Git path in VS Code, open File → Preferences → Settings and search for Git: Path
. This setting lets you specify the absolute path to the Git executable that works with your custom GitHub domain.
Alternatively, you can add or update the git.path
setting directly in your settings.json
file to ensure VS Code uses the correct Git binary for all repository operations.
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 displays the relevant information.
- Select Ctrl + K + O.
- Select folder.
Initialize new repository
Use the following procedure to create a local source code repository with git
.
Select source control from the activity bar, or use the key combination of Ctrl + Shift + G.
Select Initialize repository.
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.
- Select source control from the activity bar.
- Select ellipsis (...) next to Source Control.
- Select Branch -> Create Branch.
Commit changes locally
Once you make changes to files on your branch, commit the changes.
Select source control from the activity bar.
Enter your commit message, then select Commit.
Push a local branch to GitHub
- Select the Source Control icon from the activity bar.
- 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 output when you use the Source control extension. This output helps debug when a command fails.
Select the Source Control icon from the activity bar.
Select the ellipsis (...) then select Show Git Output.
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 |
![]() |
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). |