Installing git

The first thing we need to do is make sure you have a working version of git on your computer, which we’ll be referring to as the local machine thoughout this tutorial. Installing git on your local machine is (hopefully) not too difficult. There are several different ways you can do it, but the simplest ones are listed below:

Once you’ve completed the installation, it’s a good idea to check that everything worked. First step is to open a terminal window.

Working at the command line

A simple option is to use Tools>Terminal from within RStudio. Alternatively you can use the Windows Command Prompt (Windows) or Terminal (Mac), or follow Jenny Bryan’s guidelines here.

Checking that Git installed

Once you have your terminal type git --version at the prompt. When I do this on my machine this is what I get:

> git --version

git version 2.19.1.windows.1

For Mac users it’s exactly the same except you open the Terminal. When I do this on my Mac I get:

> git --version 

git version 2.21.0 (Apple Git-122.2)

As long as you’re getting a message that tells you that git exists then you’re good to go.

Client or command line?

There are several methods for using git, but maybe the biggest distinction is between using the command line tools (typing commands in at the Windows Command Prompt or the Mac Terminal) and using a git client (software that has a nice graphical user interface). In the long run it’s probably worth using a git client: as Jenny Bryan says, it will spare you the tediousness of “command line bullshittery”. GitKraken is a fairly popular option, but RStudio now has a nice git client built in, so you might want to explore that.

That being said for our purposes we’re going to use the command line. That’s not because we want to be “hardcore” but because most git clients are built for people who already understand git, and so the user interface is designed to show you “everything at a glance”, and (for me at least) the visual complexity of it is overwhelming. Because this is just a “getting started” tutorial we’ll just stick to some simple commands.

Configuring git

In a moment we’ll get you to sign up for an account with GitHub, but while we’re here at the command line, we might as well make a few settings. You can tell git who you are by using the git config command. For me, that means I do this:

git config --global user.name 'Danielle Navarro'
git config --global user.email 'd.navarro@unsw.edu.au'

If possible, I suggest using an university email address if you have one for reasons mentioned in the next section. Jenny Bryan has some very good advice about some important config settings you can play with. You can see more about what the various options are with this command:

git config --global --list

Getting a GitHub account

The next step in the process is setting up an account with a service that hosts remote git repositories for you in the cloud. There are many different services, but we’ll use GitHub for this. Go to the GitHub website at https://github.com/ and follow the sign up instructions. Some notes:

Cloning other people’s repositories

If you learn nothing else about GitHub, it’s useful to be able to download and use other people’s repositories. Let’s download the repository that contains most of the content for the summer school.

First, make a folder on your Desktop called CHDSS that will contain all of your work for the summer school. Having it on your desktop will make life easier for everyone when we come around to answer questions. Now open up a terminal window and navigate to your CHDSS folder within that terminal. For me, I open the terminal using Tools>Terminal then type cd Desktop/CHDSS. If you’re using Windows the command will be something like:

> cd C:\Users\Desktop\CHDSS

Now that you’re in the folder where you’d like to put the repository, clone the repository by typing the following at the command line:

> git clone https://github.com/cskemp/chdss2019_content 

You should see something like the following:

Cloning into 'chdss2019_content'...
remote: Enumerating objects: 108, done.
remote: Counting objects: 100% (108/108), done.
remote: Compressing objects: 100% (67/67), done.
remote: Total 108 (delta 16), reused 99 (delta 10), pack-reused 0
Receiving objects: 100% (108/108), 9.64 MiB | 3.83 MiB/s, done.
Resolving deltas: 100% (16/16), done.

The repository was cloned into a folder called chdss2019_content that now lives within the CHDSS folder on your desktop. If you open up the new folder you’ll see summer school files that we’ll be working with over the course of the week.

Backing up your work to GitHub

Let’s now make your own repository. Suppose you’re about to start a new project that you’re going to call summerschool. What you’d like to do is keep all your work associated with this project in a folder called summerschool, and you want it to be backed up in the cloud (and ideally, to automatically keep track of the history, so you can go back to earlier versions if you want). That’s something you could do with a combination of Dropbox and Time Machine, but let’s do it with git and GitHub!

Creating the repository on GitHub

The way that git “thinks” of things is to imagine that the version of your work on the remote machine (GitHub) is the origin of the project, and the version on your local machine is your copy of that project, so let’s mirror that logic. Go to to your GitHub homepage (for me that’s https://github.com/djnavarro), and select “new repository” as shown below: