1.2 Introduction to Git and GitHub

Open the slides in a new tab here.

Exercises

  1. Fork the repo at https://github.com/louisahsmith/epi590r-in-class by clicking “Fork” in the upper right.

    On the next page, click “Create fork”. You only need the main branch, so keep that box checked. Forking a repository creates a copy that belongs to you.1 This is what you want to do, for example, if you want to make some changes to an R package that someone else has written. You don’t have the ability to change the original repository, but you can pull any future changes the owner makes so that yours is always up to date, and you can ask them to pull in to their version any changes that you make (a pull request).

  2. On your fork of the repository, click the green “Code” button. We are going to clone the repository to your computer using HTTPS. HTTPS should already be underlined, but if, not, select it. Copy the URL (this should have your username, not mine!).

  3. Open up RStudio. Go to File > New Project. Choose “Version Control” then “Git” on the next page.

  4. Paste the URL you copied earlier. You can name the project directory whatever you want, but I find it’s easiest if it has the same name as the repo. Then choose where you want to store the project.2 You can browse the file system on your computer to do so. For me, this will create the folder /Users/l.smith/Documents/Teaching/Emory/epi590r-in-class/ and everything in the repo will be downloaded to that folder. Write down this path somewhere if you can’t remember it, so you can find it later!

    You can select “Open in new session” if you have already been doing something in R and want to keep that other RStudio window open. Then “Create Project”.

  5. From the filepane in RStudio, open README.md. Write your name in the file and save.

  6. In your Git pane, you’ll see that file pop up because it has been modified (M). When you click on the checkbox, you are staging the file.3 Then click “Commit”.

  7. You’ll see a diff of the changes you made to that file. If you don’t like them, you can revert. Add a commit message to explain what changes you’ve made. Then “Commit”, close the new window that opens, and then “Push”.4

  8. Go back to your web browser to check your repo! What do you notice?

Resources