Skip to content
This repository has been archived by the owner on Nov 17, 2019. It is now read-only.

Tutorial: Git

Kevin Zhang edited this page Jan 30, 2018 · 5 revisions

This document is mainly about setting up GitHub. See here for GitHub basics. Since setting up ssh makes interventions easier, we recommend you to setup ssh keys on your machine.

SSH Setup

Official Guide

Below is a compiled guide from the pieces in the link above.

Check for Existing SSH Keys

Link

SSH Keys are secure local keys that you can register on GitHub so that you don't have to enter your credentials each time you're accessing a remote repository. By setting up an SSH connection and registering the credentials on GitHub itself, all the verification/identification steps are taken care of by the SSH agent and you can simply push/pull the code.

In order to check:

ls -al ~/.ssh

Sample Output:

ls -al ~/.ssh
total 32
drwx------  2 jamiecho jamiecho 4096 Sep  9 22:58 .
drwxr-xr-x 83 jamiecho jamiecho 4096 Oct  1 18:05 ..
-rw-------  1 jamiecho jamiecho 3247 Jul 27 17:17 id_rsa
-rw-r--r--  1 jamiecho jamiecho  747 Jul 27 17:17 id_rsa.pub
-rw-------  1 jamiecho jamiecho 6870 Oct  1 02:56 known_hosts
-rw-------  1 jamiecho jamiecho 6426 Sep  9 21:56 known_hosts.old

You should find any one of id_dsa.pub, id_ecdsa.pub, id_es25519.pub, id_rsa.pub, ...

However, in most cases (i.e. new to setting up the environment), you'll be setting up Git in a computer without preconfigured ssh-keys. In this case, you should generate a new SSH key. This step is explained in the next section.

Generating a new SSH key

Link

  1. Generate the key by running the command below in the terminal (Do not copy-paste the below script directly):

    ssh-keygen -t rsa -b 4096 -C "[email protected]"
  2. When you're prompted to "Enter a file in which to save the key," press Enter.

    Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

    This accepts the default file location.

  3. At the prompt, type a secure passphrase. For more information, see Working with SSH key passphrases.

    Enter passphrase (empty for no passphrase): [Type a passphrase]
    Enter same passphrase again: [Type passphrase again]

Adding the SSH Key to SSH-Agent

  1. Ensure ssh-agent is enabled:

    # start the ssh-agent in the background
    eval "$(ssh-agent -s)"
    Agent pid 59566 # sample output
  2. Add your SSH Key to the ssh-agent:

    ssh-add ~/.ssh/id_rsa

Adding the SSH Key to your Github Account

Link

  1. Install Xclip, which is a program that allows you to copy/paste things with CLI.

    # install xclip
    sudo apt-get install xclip
    
    # copy id_rsa.pub to clipboard
    xclip -sel clip < ~/.ssh/id_rsa.pub	
  2. Go to your Profile Page, and click Settings.

  3. In the user settings sidebar, click SSH and GPG keys.

  4. Click New SSH key or Add SSH key.

  5. In the "Title" field, add a descriptive label for the new key. For example, if you're using a personal Mac, you might call this key "Personal MacBook Air".

  6. Paste your key (from step 1) into the "Key" field.

  7. Click Add SSH Key.

  8. If prompted, confirm your GitHub password.