Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use а private repository with VSCode?

A novice here, please type a small instruction describes how to use a private GitHub repo in VSCode

like image 363
Olek Avatar asked Apr 14 '19 03:04

Olek


3 Answers

To configure a private repo, you first need to generate a public/private RSA key pair on your dev machine to be able to establish an ssh connection to your repo instead of an HTTP connection.

Just install Git for Windows in your development environment. During installation, please make sure that you have checked the option to include git bash, as you'll need it to create this key. Once installed, right click on your Windows user folder, select on Open git bash and then just run ssh-keygen (or if you are using Linux, you can just ssh-keygen) and go through the wizard.

This step will create a hidden .ssh folder that contains your public/private RSA key pair. Navigate to that folder.

The goal here with these keys is to configure your public key on GitHub. Open your id_rsa.pub file with notepad and copy its entire content. Then go to GitHub and under your user Settings > SSH keys just add a key and paste your entire public key plus an arbitrary name.

Now restart VS Code and press CTRL+ ' (Backtick) to open PowerShell and then run:

In case you haven't cloned your repo:

To Upload changes to your repo:

  • git add .
  • git commit -m "{Name for this commit}"
  • git push {Repo Origin name (default = Origin)} {Branch Name (Default = Master)}

Note. {} are for reference, do not include them in your commands.

VS Code has built-in support for Source Control, so if it is configured, VS Code will automatically detect changes and get them ready to commit with just a commit message and click. Also, there's a really good VS Core extension called GitLens. This can help you to 1-click push

That should do it. 😃

like image 111
Daniel Lozano Avatar answered Oct 21 '22 12:10

Daniel Lozano


As of now (july 2019, not sure when this got added exactly) you can do this from within VSCode, just hit F1 in windows or ctrl++P (or ++P on mac) to access the command palette of VSCode, then type or select Git: Clone and finally enter the URL of your repository, so something like https://github.com/MY_USERNAME/MY_PROJECT.git, finally choose the folder you want to use for your cloned repository (open the main folder that contains all your projects, no need to manually create a sub folder for the project itself, git will do this for you using the projects name)

To find your exact repository URL, open the projects github page and click on the green button on the top right that says "Clone or download", if you wonder if you should use HTTPS or SSH check out the github documentation

like image 20
chrisweb Avatar answered Oct 21 '22 13:10

chrisweb


I had trouble with cloning a private repository from Github with VSCode. In my case the problem was that I followed Github docs instructions to generate SSH keys with Ed25519 algorithm and using these keys (id_ed25519.pub) with VScode and Github did not work for me.

I generated new keys with the RSA algorithm:

ssh-keygen -t rsa -b 4096 -C "[email protected]"

and after adding id_rsa.pub to my Github account settings VSCode started working with private repositories.

like image 3
Kennet Myllykoski Avatar answered Oct 21 '22 11:10

Kennet Myllykoski