2. git and GitHub

Objectives
  • Learn how branches work in git.
  • Understand the differences between git and GitHub.
  • Use GitHub to collaborate with others on a project.

This unit covers more branching in git and how to collaborate on GitHub. As some of you are more comfortable with the command line and some prefer the GUI, I’ve provided two copies of the tutorials: one that uses GitHub Desktop (GUI) and one that uses the command line interface. Both tutorials cover the same material; feel free to choose the one you’re most comfortable with.

Command Line

Prerequisites

If you’ve never used git on the command line, you’ll first need to set up some global configurations. Namely, you’ll need to tell git what your name and email are. To do that, open a terminal and run:

git config --global user.name "YOUR NAME"
git config --global user.email "YOUR_EMAIL_ADDRESS"

For entering longer commit messages (you’ll learn what this means in Exercise 1) we’ll need to tell git what text editor to use. By default git will use vim, which can be tricky to understand for new users. For the purposes of this tutorial, we’ll use the more user-friendly nano. To do that, run the following in your terminal:

git config --global core.editor nano
Note

If you wish to reset to the default editor after the tutorial is over, run:

git config --global --unset-all core.editor

Tutorials

  • Part 1: Practice with git on a local repository
  • Part 2: Interacting with remote repositories on GitHub
  • Part 3: Collaborating in GitHub using the Fork and Pull Model

GitHub Desktop

Prerequisites

In order to do the GUI version, you first need to install GitHub Desktop if you don’t have it already.

1. Install GitHub Desktop

For this tutorial we will be using GitHub Desktop. To install:

  1. Go to https://github.com/apps/desktop.
  2. Click the “Download now” button.
  3. What you do next depends on your operating system:
  • If you’re on a Mac:
    1. Click “Download for Apple silicon” or “Download for Intel chip” depending on your processor. If you’re not sure what processor you have, click the apple button in your Menu bar then “About This Mac”. Look at the “Chip” entry in the window that pops up. If it says, “Apple M…” you have Apple silicon. If it says, “Intel …” you have an Intel chip.
    2. Clicking one of the download buttons will download a .zip file that starts with “GitHubDesktop”. Once it’s finished downloading, open it. The file will unzip and open a Finder window.
    3. Move the GitHub Desktop icon into your Applications folder in Finder.
    4. Open GitHub Desktop as you would any other application (e.g., by going to Launchpad and clicking on the GitHub Desktop icon).
    5. The first time you open GitHub Desktop you will be prompted with a warning, “‘GitHub Desktop’ is an app downloaded from the internet. Are you sure you want to open it?” Click “Open”.
  • If you’re on a Windows machine:
    1. Click “Download for Windows (64 bit)”. This will download a file called “GitHubDesktopSetup-x64.exe”.
    2. Once the file downloads, it will automatically install and open GitHub Desktop.

2. Setup GitHub Desktop

The first time you open GitHub Desktop you will need to sign into GitHub.

  1. Click “Sign in to GitHub.com”. If you do not have an account yet, click “Create your free account”.
  2. Follow the on-screen instructions to sign in.
  3. After you sign in, GitHub Desktop will ask you to “Configure Git”. We recommend you select the option “Use my GitHub account name and email address”. Click “Finish”.

You will next be prompted with a “Let’s get started!” screen that will ask you to add a repository to GitHub Desktop. Stop here and go to Part 1.

Tutorials

  • Part 1: Practice with GitHub Desktop on a local repository
  • Part 2: Interacting with remote repositories on GitHub
  • Part 3: Collaborating in GitHub using the Fork and Pull Model

Lectures

9-10-26

Overview of Git and GitHub; intro to branches in local repository

9-17-26

More on merging branches: rebasing, squash and merger, resolving merge conflicts

9-24-26

Creating and managing remote repositories on GitHub; creating pull requests