Bootstrap FreeKB - GitHub - Clone a GitHub repository in VSCode
GitHub - Clone a GitHub repository in VSCode

Updated:   |  GitHub articles

Before you can clone a GitHub repository in VSCode, you will first need to install Git on your local PC.

In VSCode, select Terminal > New Terminal and enter these commands.

C:\Program` Files\Git\bin\git config --global user.name "Your Name"
C:\Program` Files\Git\bin\git config --global user.email "your@email"

 

These commands should create the C:\Users\your_username\.gitconfig file on your PC. The .gitconfig file should look like this.

[user]
	name = John Doe
	email = john.doe@example.com

 

Let's use SSH keys to authenticate to GitHub. First check to see if you have SSH keys on your laptop. If you do, they will be located in the C:\Users\your_id\.ssh directory, something like this.

C:\Users\your_id\.ssh\id_ed25519
C:\Users\your_id\.ssh\id_ed25519.pub

 

If you do not have SSH keys, the ssh-keygen command can be used to create the SSH keys.

ssh-keygen -t ed25519 -N ' ' -C 'my-SSH-key' -f 'C:\Users\your_id/.ssh/id_ed25519'

 

Open the id_ed25519.pub key in notepad, and something like this should be displayed. Copy this to your clipboard.

ssh-ed25519 AAAACabc123lZDI1NTE5AAAAIB7PlABC12324yz6p+Lklj5uErABC123MVcz1ZtjBrwX my-SSH-key

 

Then go to github.com > Manage account > SSH keys > Add key, and paste from your clipboard.

Then issue the following command in Terminal to create the “config” file. I use the PowerShell New-Item cmdlet to ensure the config file is type file, not a TXT file.

New-Item C:\Users\JohnDoe\.ssh\config

 

And then update the config file to have the following.

Host github.com
    IdentityFile /c/Users/JohnDoe/.ssh/id_ed25519

 

If your repository only has one branch, such as the "main" branch, or if you want to clone the default branch, which is typically the "main" branch, in the left panel of VSCode, select Source Control and select Clone Repository.

 

Enter the GitHub URL of the repository you want to clone. You will be prompted to select a folder on your local PC to clone the repository into. Select a folder, such as C:\Users\john.doe\VSCode\GitHubRepos\Stage.

 

Or, issue the git clone comamnd in Terminal.

C:\Program` Files\Git\bin\git clone https://github.com/JohnDoe/Stage C:\Users\JohnDoe\GitHubRepos\Stage

 

It's probably a good idea to use the git branch --all command to see what branch you are on. The git checkout command can be used to switch branch if you want to select a different branch.

> C:\Program` Files\Git\bin\git --all
  development
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/feat/logging
  remotes/origin/master

 

The files in the GitHub repository should now be listed in VSCode!

 

Let's say you make a change to one of the files from the clone repository in VSCode. I added "VSCode is pretty cool!".

In the left panel of VSCode, select Source Control > Commit to make a commit.

 

When you are ready to push the commit to GitHub, select Sync.

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 883f3a in the box below so that we can be sure you are a human.