We want to use github and code with Visual Studio Code using its git GUI that comes intergrated.
Git install (on macOS)
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.
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]
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
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 ed25519 -C "[email protected]"
This creates a new ssh key, using the provided email as a label with the new GitHub ECDSA security standard based on elliptic curve cryptography.
When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.
Start the ssh-agent in the background
eval "$(ssh-agent -s)"
If you're using macOS Sierra 10.12.2 or later, you will need to modify your
~/.ssh/configfile to automatically load keys into the ssh-agent and store passphrases in your keychain.
If the file doesn't exist, create it:
Then modify the file to contain the following lines. If your SSH key file has a different name or path than the example code, modify the filename or path to match your current setup.
Host * AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_ed25519
Open (if not create it) your gitconfig with
open ~/.gitconfig to add your git preferences
[user] name = your_name email = your_github_email [core] editor = code [filter "lfs"] clean = git-lfs clean -- %f smudge = git-lfs smudge -- %f process = git-lfs filter-process required = true [diff] tool = vscode [difftool "vscode"] cmd = code --wait --diff $LOCAL $REMOTE [merge] tool = vscode [mergetool "vscode"] cmd = code --wait $MERGED [github] user = your_github_username token = your_github_token
Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
Add the SSH key to your GitHub account
On the terminal type:
cat ~/.ssh/id_ed25519.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
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
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Troubleshooting Visual Studio code
Possible error 1
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:
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
Possible error 2
/Users/USER/.ssh/config: line 16: Bad configuration option: usekeychain
add an additional config line to your
Host * section:
Host * IgnoreUnknown UseKeychain
Possible error 3
Updating your credentials via Keychain Access