Introduction to Git & GitHub

Jump to Table of Contents

Overview

Git is used extensively worldwide for many type of software and internet and other types of publishing projects (among others). This article provides an introduction to Git and probably the most popular central git repository (GitHub).

Some Publishing Notes

These pages are based on a presentation I created for a group of fellow Makers at the MakerPlace at the Midland Public Library in Midland, Ontario. It is based on, but not a conversion of, a PowerPoint presentation. It would have taken as much work, or more, to convert what I used for the live presentation as I would need to add captions and narration to the videos (which in a web form are easily divided into screenshots with explanations) to satisfy my desire for an accessible website. In addition simply exporting a presentation to HTML5 tends not to be as browser agnostic as I would want.

Version Control and Beyond

Git Ecosystem (Where Git is Used and Why)

Git is Everywhere

Shading map of world with GitHub users and commits by country

The shading of the map illustrates the number of users as a proportion of each country’s Internet population. The circular charts surrounding the two hemispheres depict the total number of GitHub users (left) and commits (right) per country.Author: Stefano desabbta, license: CC BY-SA 4.0

Why Git is Used

  • Used / created for Linux kernel development
  • The base technology is both gratis and libre
  • Version control and Source Code Management (Managing collaboration)
  • Readily available cross-platform tools
  • Distributed — users have their own copy
  • Normally only changes are pushed or pulled to the ‘remotes’
  • Developers are able to modify / enhance Git (as it is open source).
  • Fast and light
  • Easy branching and merging

Types of Projects (Sample)

  • Linux and Cross-Platform Software (Open Source)
    • Linux Kernel, XOrg/Wayland, linux-utils, and Embedded Devices (OpenWrt)
    • Inkscape, GIMP, LibreOffice, Zim, KeepassXC, VSCode, …
  • Web Applications (Open Source & Proprietary)
    • Many are based on the Python, Node.js, Ruby, or Golang ecosystems which mostly use Git
  • DevOps / IaaS (Infrastructure as a Service); Often In-house
    • CircleCI, TravisCI, Jenkins and so on are all oriented towards git-based Continuous Integration and Continuous Deployment
    • Packer, Terraform, Ansible, Puppet, and Chef all aim to make infrastructure configuration a form of software
  • Websites, and Documents
    • Netlify has become very popular for static website generation and publishing; others uses Hugo with old-school deployments or GH Pages
    • The Raspberry Pi Curriculum, Awesome Lists, and Open Source Software documentation projects all use Git for collaborating on documents

Why Use Either GitHub or Their Competition

  • Git emphasizes collaboration and sharing; central git makes it easy
  • Central git services promote Continuous Integration (CI) and Continuous Deployment (CD)
  • Allows both public and private repositories hosted on ‘cloud’ servers
  • Usually have many integrations with other development and project management tools.
  • Other developers are more likely to find your project.
  • In short they make life easier, especially when collaborating
  • GitHub is the best known central git service
  • Another two major central git services are: GitLab and Bitbucket

Signup is Easy

Just got to https://github.com fill out the form, click ‘Sign Up’ and follow the prompts.

GitHub Provides Learning Materials

screenshot of GitHub welcome screen after signup

screenshot of GitHub course choices if you go to 'GitHub Learning'

Demonstration

Edit, Test, Website (CI/CD) Cycle

Git and Visual Studio Code Setup on Windows

Setup Overview

  • Install Chocolatey – this makes the rest of the installation easier and has added benefits
  • Install “Git for Windows”, “Git Credential Manager for Windows”, and Visual Studio Code*
  • Configure “Git for Windows” & “Git Credential Manager for Windows”
  • Add Extensions for Visual Studio Code
  • Configure Visual Studio Code
  • Test with provided tutorials.

Install Chocolatey

Chocolatey is software that makes it easy to install other software (and remove or update the software you install). If in doubt, check the official install guide at https://chocolatey.org/install

  1. Execute the following in a Administrator PowerShell terminal (right click the start menu icon and select “Windows PowerShell (Admin)”, if you are using Windows 10):

    Set-ExecutionPolicy AllSigned -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
    
  2. Exit the PowerShell terminal

  3. Launch another Administrator PowerShell terminal

  4. Execute: choco install chocolateygui — This will give you a graphical interface for using Chocolatey

Install Visual Studio Code, Git for Windows, and Git Credential Manager

  1. In an Administrator PowerShell terminal Execute choco install –y vscode git git-credential-manager

Configure Git for Windows (Recommendations)

Execute the commands in a regular PowerShell or Command Prompt

CommandWhy
git config --global credential.helper = managerUse Git Credential Manager for Windows
git config --global core.filemode = falseIgnore permissions changes due to Windows filesystem
git config --global core.autocrlf = trueUse Windows line-endings when checking out, and convert the line-endings to Unix-style endings on commit
git config --global pull.ff = onlyOnly “fast-forward” pulls (that means the branch you are pulling into won’t be altered, except the addition of new commits when you pull; you can still “git fetch” and merge if necessary).
git config --global core.editor = “code --wait"Use “Visual Studio Code” as default editor instead of vim or nano (which are harder for beginners to use)
git config --global user.name = “Your Name”Default user information (name) for commits
git config --global user.email = “yourgithubemail@example.net”Default user information (email) for commits

Install Extensions for Visual Studio Code (Recommendations)

  1. Execute the commands in a regular PowerShell or Command Prompt
CommandWhy
code --install-extension eamodio.gitlensGitLens is a useful set of enhancements for working with Git
code --install-extension GitHub.vscode-pull-request-githubManage Pull Requests from within Visual Studio Code
code --install-extension donjayamanne.githistoryView Git History and manage a git repo in Visual Studio Code
  1. Or you can install them using the GUI after launching Visual Studio Code.

Learn and Use Visual Studio Code

  1. Next you want launch Visual Studio Code, and read the ‘Welcome’ screen and follow the links that suit what you need to learn.
  2. Checkout Working with GitHub on the Visual Studio Code website.

Learn and Use Git

To borrow from the Visual Studio Code documentation: If you are new to Git, the git-scm website is a good place to start with a popular online book, Getting Started videos and cheat sheets.

The VS Code documentation assumes you are already familiar with Git.

Table of Contents

  1. Overview
  2. Some Publishing Notes
  3. Version Control and Beyond
    1. Git Ecosystem (Where Git is Used and Why)
      1. Git is Everywhere
      2. Why Git is Used
      3. Types of Projects (Sample)
    2. Why Use Either GitHub or Their Competition
    3. Signup is Easy
    4. GitHub Provides Learning Materials
  4. Demonstration
  5. Git and Visual Studio Code Setup on Windows
    1. Setup Overview
    2. Install Chocolatey
    3. Install Visual Studio Code, Git for Windows, and Git Credential Manager
    4. Configure Git for Windows (Recommendations)
    5. Install Extensions for Visual Studio Code (Recommendations)
  6. Learn and Use Visual Studio Code
  7. Learn and Use Git
  8. Table of Contents