Wilson Mar bio photo

Wilson Mar

Hello. Hire me!

Email me Calendar Skype call 310 320-7878

LinkedIn Twitter Gitter Google+ Youtube

Github Stackoverflow Pinterest

Create and use certificates to push to GitHub


Overview

This is a hands-on step-by-step tutorial on the quickest way for “newbies” to generate a public certificate for GitHub to reference to accept changes pushed up from git clients.

Get Yourself on GitHub

The following steps require switching between GitHub and Terminal (by pressing command+Tab on Mac and Alt+Tab on Windows) until the icon for the app you want is highlighted.

The following instructions assumes this is the first time you’re running this.

  1. On an internet browser on GitHub.com, create an account if you don’t already have one.

    Throughout this tutorial, you will be replacing your own account name with the stand-in example of:

    hotwilson

    SSH Key into GitHub

  2. Switch to a Terminal to create a public and private key. To use default parameters:

    ssh-keygen

    The response:

    Generating public/private rsa key pair.
    Enter file in which to save the key (/Users/hotwilson/.ssh/id_rsa): 
    
  3. Press Enter repeatedly to accept defaults until you see:

    Your public key has been saved in /Users/hotwilson/.ssh/id_rsa.pub.
    The key fingerprint is:
    SHA256:lsjVHl3cuL/xRvbFzyWtSaFxVI59oDNyAuxicJeWqOs hotwilson@Wilsons-MacBook-Pro.local
    The key's randomart image is:
    +---[RSA 2048]----+
    |       o.o   .o+.|
    |    . o *o . o+=.|
    |     + +. = *...+|
    |    ..oo.o =.o+ .|
    |     oo.S .  + = |
    |    .  .    . o.O|
    |   .         . BO|
    |    E         o.*|
    |               . |
    +----[SHA256]-----+
    

    PROTIP: The account name shown above would be substituted with your own account name. But it doesn’t matter because it’s the certificates generated that are used for authentication.

  4. Get the public key in the .ssh folder into your Mac’s clipboard:

    cat ~/.ssh/id_rsa.pub | pbcopy

  5. Press command+Tab to switch back to the internet browser showing GitHub.
  6. Click the icon for your account at the upper-right of the screen to select Settings.
  7. Click on SSH and GPG keys.
  8. Click on New SSH key green button.
  9. Click inside the field labeled Key so its border turns blue.

    PROTIP: You can leave the Label field blank. Others put a date there.

    PROTIP: Enterprise versions of GitHub use single-sign-on capabilities that leverage corporate authentication mechanisms where you don’t have to do this.

  10. Click on Add SSH key green button.

    You can now upload from your laptop to any repo for your GitHub account.

    Create container path

  11. In a Terminal window:
  12. Create a folder to house your development projects:

    mkdir ~/gits && cd gits

    PROTIP: Instead of gits, some use dev or Sites or Projects to house related software development work, separate from other folders such as “Desktop” and “Document” under your MacOS user account folder.

  13. Create a folder representing your GitHub account to house new websites to be created (substituting “hotwilson” with your GitHub user name):

    mkdir hotwilson

  14. Set permissions for your MacOS user to write to the new folder (subsituting your own user instead of “wilsonmar” and GitHub account name instead of “hotwilson”):

    sudo chown -R wilsonmar hotwilson
    sudo chmod -R +rwx hotwilson

  15. Type in your password when prompted.

  16. Navigate into the containing folder where a new directory is automatically built:

    cd ~/gits/hotwilson

    Get batch utility from GitHub

  17. Get the Bash script that automates the instructions described below:

    wget https://github.com/wilsonmar/git-utilities/blob/master/foundation-website-init.sh

    The response ends with a line like this:

    2017-09-28 03:26:42 (441 KB/s) - ‘foundation-website-init.sh’ saved [46178]
    

    Alternately, download the whole repo:

    git clone https://github.com/wilsonmar/git-utilities --depth=1 && git checkout HEAD foundation-website-init.sh

  18. Open for edit the file using the nano text editing program that comes with MacOS:

    nano foundation-website-init.sh

    Alternately, you can use subl, atom, vscode, or IDE already installed.

  19. Edit the file to specify your account and website name:

      GITHUB_USER="hotwilson"
      REPONAME='website1'
    
  20. Save the changes.

  21. Run the script that performs what is described below:

    ./foundation-website-init.sh

Processing

The following steps are performed either manually or by the Bash script downloaded above.

  1. Navigate into the containing folder for Foundation to build a new directory, such as:

    cd ~/gits/hotwilson

    Starting over?

    If you already created a folder using the script or manually…

  2. If you have a Terminal window running the localhost website, click on that Terminal screen and press control+C.

  3. Remove (delete) the generated folder (replacing “website1” with your site’s name):

    rm -rf website1

    By deleting the whole folder, makes the automation script “idempotent”. In other words, running it would end up the same.

    Get website local

  4. Create a folder containing your repo in GitHub (subsituting “hotwilson/website1” with your own account and repo name):

    git clone https://github.com/hotwilson/website1

    The response for just .git folder and README.md in the repo:

    Cloning into 'website1'...
    remote: Counting objects: 3, done.
    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    Unpacking objects: 100% (3/3), done.
    

    gitignore website folder

    Make sure that folders are not uploaded

  5. Create or open for edit the .gitignore file using the nano text editing program that comes with MacOS:

    nano .gitignore

    Alternately, you can use subl, atom, vscode, or IDE already installed.

  6. Edit the file to specify your account and website name:

    website1
    
  7. Save the changes.