Setup Github + VSC

0

Full article

Motivation

We want to use github and code with Visual Studio Code using its git GUI that comes intergrated.

Git install (on macOS)

git --version

If you don’t have it installed already, it will prompt you to install it.

If you want a more up to date version, you can also install it via a binary installer. A macOS Git installer is maintained and available for download at the Git website.

First-Time Git Setup

Now that you have Git on your system, you’ll want to do a few things to customize your Git environment. You should have to do these things only once on any given computer; they’ll stick around between upgrades. You can also change them at any time by running through the commands again.

Your Identity:
The first thing you should do when you install Git is to set your user name and email address. This is important because every Git commit uses this information, and it’s immutably baked into the commits you start creating:
git config --global user.name "John Doe"
git config --global user.email [email protected]

Your Editor
Now that your identity is set up, you can configure the default text editor that will be used when Git needs you to type in a message. If not configured, Git uses your system’s default editor.
git config --global core.editor code

Checking Your Settings
git config --list

Integrate Visual Studio Code with Git-hub

To run git commands in the terminal with github, we need to have associated an SSH key. Before you generate an SSH key, you can check to see if you have any existing SSH keys.

Checking for existing SSH keys
Enter ls -al ~/.ssh to see if existing SSH keys are present:

By default, the filenames of the public keys are one of the following:

id_dsa.pub
id_ecdsa.pub
id_ed25519.pub

id_rsa.pub

If you don't have an existing public and private key pair, or don't wish to use any that are available to connect to GitHub, then generate a new SSH key.

Generating a new SSH key
Open Bash and paste the text below, substituting in your GitHub email address:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
This creates a new ssh key, using the provided email as a label.

When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.

Adding your SSH key to the ssh-agent
If you are using the Bash shell (including Git Bash), start ssh-agent with:

eval `ssh-agent`

Add your SSH private key to the ssh-agent: ssh-add ~/.ssh/id_rsa

Add the SSH key to your GitHub account
On the terminal type: cat .ssh/id_rsa.pub and copy your ssh key.

Now go to Github and in the upper-right corner of any page, click your profile photo, then click Settings -> SSH and GPG keys -> New SSH key

Test connection
Enter the following: ssh -T [email protected]

You may see a warning like this:
The authenticity of host 'github.com (IP ADDRESS)' can't be established. RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. Are you sure you want to continue connecting (yes/no)?

or like this:
The authenticity of host 'github.com (IP ADDRESS)' can't be established. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you want to continue connecting (yes/no)?

Verify that the fingerprint in the message you see matches one of the messages in step 2, then type yes:

Hi username! You've successfully authenticated, but GitHub does not
provide shell access.

Troubleshooting Visual Studio code

In some cases you'll see something like this when working with the GUI on VSC:
Git: Permission denied (publickey)

Here is how to fix it:
If you are using the Bash shell (including Git Bash), start ssh-agent with:

eval `ssh-agent`

As of macOS Sierra 10.12.2 Apple added an ssh_config option called UseKeychain which allows a 'proper' resolution to the problem. Add the following to your ~/.ssh/config file:

Host *
   AddKeysToAgent yes
   UseKeychain yes

How can I verify that the public key I uploaded is the same key as I have locally?
You can verify the fingerprint of the public key uploaded with the one displayed in your profile through the following ssh-keygen command run against your public key using the bash command line.
ssh-keygen -l -E md5 -f ~/.ssh/id_rsa.pub







Comments