Skip to main content Link Search Menu Expand Document (external link)

Github

This article will teach you how to use Github.

Table of contents

  1. What is Github?
  2. Get started with GitHub
  3. Using Git to authenticate with GitHub
    1. HTTPS URLs Cloning
    2. SSH URLs Cloning

What is Github?

GitHub is a hosting service for Git repositories with a web-based graphical interface. Essentially, it simplifies the usage of Git for version control and collaboration by individuals and teams.

Get started with GitHub

  • First you need to Sign up for a free GitHub account.
  • Setup you git username and email on your device.

    a. In every repository.

       $~> git config --global user.name "Juan Dela Cruz"
       $~> git config --global user.name 
      => Juan Dela Cruz
       $~> git config --global user.email "juan_dela_cruz@gmail.com"
       $~> git config --global user.email 
      => juan_dela_cruz@gmail.com
    

    b. Single repository.

       $~> git config user.name "Juan Dela Cruz"
       $~> git config user.name 
      => Juan Dela Cruz
       $~> git config user.email "juan_dela_cruz@gmail.com"
       $~> git config user.email 
      => juan_dela_cruz@gmail.com
    

    For commits you push from the command line, you can set your commit email address in Git as shown above. For web-based Git operations, you can set your commit email address on GitHub.com.

Using Git to authenticate with GitHub

When connecting to a GitHub repository via Git, you must login with GitHub using HTTPS or SSH.

HTTPS URLs Cloning

When you use the command line to git clone, git fetch,git pull, or git push to a remote repository using HTTPS URLs, Git will prompt you for your GitHub account and password. When Git asks for your password, enter your personal access token.

Creating Personal Access Token

  • Verify your email address in Github (if it hasn’t been verified yet).
  • Click your profile photo in the upper-right corner of the page, then click Settings.
  • In the left sidebar, click Developer settings.
  • Select Generate new token, then click Generate new token (classic).
  • Fill out the Note for token description.
  • Set the token expiration by selecting the Expiration drop-down menu, then click a default option or use the calendar picker.
  • Select the scopes you’d like to grant this token. For now, let’s select all.
  • Lastly, click Generate token.

After creating personal access token, you may now clone using HTTP’s URL.

Example usage:

 $~> git clone https://github.com/USERNAME/REPO.git
Username: YOUR_USERNAME
Password: YOUR_TOKEN

SSH URLs Cloning

SSH URLs offer safe access to a Git repository over SSH. To utilize these URLs, you must first create an SSH keypair on your computer and then add the public key to your GitHub account.

Check if you have an existing SSH key.

 $~> ls -al ~/.ssh

Check the directory listing to verify whether you have a public SSH key already. The filenames of acceptable public keys for GitHub are one of the following by default: id_rsa.pub, id_ecdsa.pub or id_ed25519.pub.

If you receive an error that ~/.ssh doesn’t exist, you do not have an existing SSH key pair in the default location.

If you don’t already have an SSH key, you must generate one.

  • Generate SSH key with ssh-keygen -t ed25519 -C "your_email@example.com".
  • When prompted to “Enter a file to save the key in”, press Enter to accept the default file location.
  • When prompted to “type a passphrase”, press Enter.
 $~> ssh-keygen -t ed25519 -C "your_email@example.com"
Generating public/private ed25519 key pair.
Enter file in which to save the key (~/.ssh/id_ed25519):
Created directory '~/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in ~/.ssh/id_ed25519
Your public key has been saved in ~/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:XxXXxxxxxXXXxx+xXX/xxxxX/xXXXxXxXxxxxXXxX your_email@example.com
The key's randomart image is:
+--[ED25519 256]--+
| .xx  . .        |
|... .x.x         |
|x ...xx          |
|..x.+.. X x .    |
|...*.+ xXX = x   |
| .+ *.x.+ = = .  |
|.x xx=.. x = .   |
|x ..x.  x . x    |
|     ... .       |
+----[SHA256]-----+

Adding SSH key to ssh-agent

Start the ssh-agent in the background.

 $~> eval "$(ssh-agent -s)"
Agent pid xxxx

For macOS Sierra 10.12.2 or later, /.ssh/config should be modified to automatically load keys into the ssh-agent and save passwords in your keychain.

 $~> touch ~/.ssh/config # if there's no '/.ssh/config' file
 $~> open ~/.ssh/config

Then add this content:

Host github.com
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_ed25519

Add your SSH private key into the ssh-agent and save your password in the keychain.

 $~> ssh-add --apple-use-keychain ~/.ssh/id_ed25519
Identity added: ~/.ssh/id_ed25519 (your_email@example.com)

Adding the SSH key to account.

  • Copy the SSH public key to your clipboard.

     $~> pbcopy < ~/.ssh/id_ed25519.pub # This will copy the contents of the id_ed25519.pub file to your clipboard
    
  • Go to Github, click your profile photo in the upper-right corner of the page, then click Settings.
  • Click SSH and GPG keys located at the sidebar’s Access section.
  • Click New SSH key or Add SSH key.
  • Fill out the Title then select authentication for type of key.
  • Paste your public key into the Key field.
  • Lastly, click Add SSH key.

You can now clone using SSH Url.

Example usage:

 $~> git clone git@github.com:USERNAME/REPO.git
Cloning into 'REPO'...
The authenticity of host 'github.com (20.205.243.166)' can't be established.
ED25519 key fingerprint is SHA256:XxXXxxxxxXXXxx+xXX/xxxxX/xXXXxXxXxxxxXXxX.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
remote: Enumerating objects: 37, done.
remote: Counting objects: 100% (37/37), done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 37 (delta 11), reused 37 (delta 11), pack-reused 0
Receiving objects: 100% (37/37), 7.35 KiB | 3.67 MiB/s, done.
Resolving deltas: 100% (11/11), done.

That is all for Github. For more information, read Github Quckstart.


Back to top

Copyright © 2020-2022 Secure Smarter Service, Inc. This site is powered by KodaCamp.