This lesson is in the early stages of development (Alpha version)

Setting Up

Overview

Teaching: 5 min
Exercises: 0 min
Questions
  • How do I get set up to use Git?

  • How do I set up my account on GitHub?

Objectives
  • Configure git the first time it is used on a computer

  • Understand the meaning of the --global configuration flag

  • Add an SSH key to a GitHub account

Prerequisites

In this lesson we use Git from the Bash Shell. Some previous experience with the shell is expected, but isn’t mandatory.

Setting Up Git

We’re going to use Git on the command line on our remote server, so we need to connect to it first, so using a terminal:

$ ssh username@servername

Don’t have a GitHub Account?

For this lesson you’ll need an account on GitHub, so if you don’t have an account on GitHub, please go and create one now.

The first time we use Git on a new machine, we need to configure it. We’re going to set some global options, so when Git starts tracking changes to files it records who made them and how to contact them.

$ git config --global user.name "Firstname Surname"
$ git config --global user.email "fsurname@university.ac.uk"

(Please use your own name and the email address you used to sign up to GitHub!)

We’re going to set Nano, a simple, minimal commaand-line text editor to be the default for when you need to edit messages.

$ git config --global core.editor "nano -w"`

If you’re already comfortable with another command-line editor, feel free to select that!

Git commands are written git action, where action is what we actually want it to do. In this case, we’re telling Git:

The three commands above only need to be run once: the flag --global tells Git to use the settings for every project on this machine.

You can check your settings at any time:

$ git config --list

Git Help and Manual

If you forget a git command, you can access the list of commands by using -h and access the Git manual by using --help :

$ git config -h
$ git config --help

While viewing the manual, remember the : is a prompt waiting for commands and you can press Q to exit the manual.

Key Points

  • Use git config with the --global option to configure a user name, email address, editor, and other preferences once per machine.

  • GitHub needs an SSH key to allow access