git and GitHub
| Objectives |
|---|
|
Prerequisites
The following should be done before doing the exercises below.
Installing git
To check if you already have git installed, open a terminal and run:
git --versionIf a version number is returned (e.g., git version 2.47.1), you can skip to the next section. Otherwise, follow the instructions below for your operating system.
Download and install Git for Windows. The default options in the installer are fine for this workshop. Git for Windows also includes Git Bash, the terminal we use in the shell lesson, so if you already have Git Bash, you already have git.
Once it’s installed, open Git Bash and run git --version to verify that it worked.
The easiest option is to install Apple’s Xcode Command Line Tools, which include git. Running git --version in Terminal should prompt you to install them if you don’t have git yet. If it doesn’t, you can install them by running:
xcode-select --installAlternatively, if you use Homebrew, you can run brew install git. See the git download page for macOS for other options.
Once it’s installed, close and reopen Terminal, then run git --version to verify that it worked.
Install git with your distribution’s package manager. For example, on Debian/Ubuntu:
sudo apt-get install gitor on Fedora:
sudo dnf install gitSee the git download page for Linux for other distributions.
GitHub authentication
In exercises 2 and 3 you will be using GitHub to “push” and “pull” commits between your local computer and GitHub’s servers. This requires authentication to be setup. For these purposes we suggest using ssh keys. Alternatively, you can log in with the GitHub CLI (gh) and use git over HTTPS instead of ssh. To set up one of these, follow the instructions here:
- Setup ssh key for GitHub
- Log in to GitHub with the GitHub CLI (alternative to ssh keys)
Git configuration
Before doing the exercises in this session, you’ll need to tell git what your name and email are, so that it creates commits with the appropriate author information. To do that, open a terminal and run the following (it doesn’t matter which directory you run these from), but replacing YOUR NAME with your name and YOUR_EMAIL_ADDRESS with your email address:
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 nanoIf you wish to reset to the default editor after the tutorial is over, run:
git config --global --unset-all core.editor