💻 Lab 03 – GitHub and Markdown

Week 01 – Day 03 - Lab Roadmap (90 min)

Author
Published

12 July 2023

📋 LAB DIFFICULTY: 😅 NOT TOO CRAZY

(The tasks themselves might not be that challenging but there are a lot of steps)

🥅 Objectives

  1. GitHub setup: Set up your GitHub account, ensuring you are ready to use GitHub for future projects.

  2. Project repository: Create a private repository for your work in this course, including the creation of a README file.

  3. Git Commands: Understand essential Git commands such as cloning a repository, uploading and downloading changes using git push and git pull, and utilizing .gitignore to exclude sensitive information from your repository.

📋 Lab Tasks

The main goal of this lab is to gain practical experience with the GitHub platform and learn how to effectively use Git for version control. We encourage you to use GitHub to store your code and, in the future, beyond this course, to collaborate with others. It might take a bit of time to get used to it, but we promise it will be worth it.

Important

This lab roadmap covers a lot of ground, and it’s common for many people not to complete all the steps during the lab. If you find yourself in that situation, don’t worry! You can continue working on it after the lab. Alternatively, we have set aside some time in tomorrow’s lecture to help you catch up.

Part 1: Welcome to GitHub (10 min)

The first thing we will do is explore GitHub. GitHub is a collaborative tool for developers with an estimated number of users of 100+ million. It allows developers to track changes in their code and collaborate straightforwardly and sustainably.

When applying to jobs related to data science, you will most likely be asked about your Git/GitHub skills. It is because they are crucial for data science teams.

Let’s get started!

🎯 ACTION POINTS

  1. Register on GitHub if you haven’t done so yet.

  2. We recommend you use a personal email address. This way, you still have access to your account if your university decides to delete your email account.

  3. Choose a meaningful username and a password. We also recommend changing the default avatar picture. If you don’t feel comfortable using your real picture, use an avatar or anything else that you feel comfortable with.

Part 2: Your GitHub profile repository (20 min)

🎯 ACTION POINTS

Now, let’s create your first git repository. We will start with a personal README repository, this special repository acts as a kinda of professional profile page.

  1. Click on the green button ‘New’ and create a new repository and name it EXACTLY as your GitHub username.

  2. Now, on the newly created repository, add a README.md file. Including a README file for each repository is a good practice, even for personal profiles. READMEs are typically written in Markdown language, which allows for easy formatting and organization of information.

  3. Customize your README file.

    • Refer to the GitHub documentation about markdown here to see how to format your README file.
    • You can get inspired by this article.
    • Here is Jon’s README for an example.

You can always edit your README file later.

Part 3: Create a repository for your files (~10 min)

Now, let’s create a repository where you will store all the files related to this course.

🧑🏻‍🏫 TEACHING MOMENT

Your instructor will follow the same steps below to create a personal repository for the course.

  1. Create a new repository from scratch. Call it lse-2023-me204.

    • On ‘Description’ write something like ‘My code for the LSE ME204 course’
    • ☑️ Check the box to ‘Add README file’
    • 🔻 On the ‘Add .gitignore’ dropdown menu, find and select ‘R’.
  2. Using the web interface, modify the README.md file to add a brief description of this course.

  3. Again using the web interface, create a new file called lab03.R and add the following code to it:

    print("I have created my first repository!")
    
    print("My name on GitHub is set to:")
    system("git config user.name")
    
    print("My e-mail on GitHub is set to:")
    system("git config user.email")

Part 4: Setup your computer to work with GitHub (50 min)

⚠️ Brace yourself, things are about to get complicated! ⚠️

Great! You have created a repository but now you need to set up your computer to be able to upload and download files from it.

If it helps, think of Git/GitHub as a Google Drive/Dropbox, only you are the one manually syncing the files.

🎯 ACTION POINTS

  1. The first thing you need to do is to ensure you have git installed on your computer! If you don’t have it, you can download it here.

  2. Before you can download (clone) your project’s repository, you will need to set up your GitHub account on your computer.

    • Open the terminal and type the following, replacing your_username with your GitHub username.
    git config --global user.name "your_username"
    • Now type the following, replacing your_email with your GitHub email address:
    git config --global user.email "your_email"
  3. You will also need to set up an SSH key to work with GitHub from your computer.

    • Follow the instructions in the official documentation carefully, to generate a new SSH key

    • Now add your SSH key to your GitHub account. Follow the instructions here.

    • Test that it works by typing ssh -T git@github.com on the prompt. You should see a message like this:

      Hi your_username! You've successfully authenticated, but GitHub does not provide shell access.
  4. Now, navigate to a folder where you want to store your project.

    • We recommend you create a folder called Workspace in your local home/Documents folder, then cd ~/Workspace.
  5. Clone your project’s repository.

    • Go to your project’s repository page on GitHub and click on the green Code button.
    • Copy the URL that appears under SSH
    • Now, on the prompt, type git clone and paste the URL you copied.
    • Press Enter and wait for the process to finish.

    If you get an error message, it’s probably because you haven’t set up your SSH key correctly. Go back to step 3 and try again.

  6. Check that your project’s folder has been created.

    • Navigate to the folder you have just cloned.
    • Check that the files you added to the repository (README.md and .gitignore) are there.
  7. On your computer, create a folder called labs inside your project’s folder.

    • Move your lab01.R, lab01-tidyverse.R and lab02.R files to this folder.
    • You can create subfolders for each lab, if you want.
  8. On the terminal, type git status. You should see a message like this:

    On branch main
    Your branch is up to date with 'origin/main'.
    
    Untracked files:
    (use "git add <file>..." to include in what will be committed)
    
        labs/
    
    nothing added to commit but untracked files present (use "git add" to track)

    This means that you have created new files, but you haven’t added it to the commit yet.

  9. Now, you need to add your changes. Simply type:

    git add labs/

    You can also use git add * to add all the changes to the commit.

  10. Good. But adding files to the commit is not enough. You also need to commit them. Type:

    git commit -m "message"

    Replace “message” with text that describes what you did in that repo. For instance, you could write “Added my lab files to the project”.

  11. You have committed the changes, but they are still on your computer. You need to push them to the GitHub repository. Type:

    git push

If you were able to complete all of that during the lab, you’re a hero! Keep using this workflow for the rest of the course, and you’ll become familiar with it in no time.

In tomorrow’s lecture, we have allocated some time to address any issues you might have with this process. So if you encounter any challenges, don’t worry, we’ll help you sort them out.

🏡 Bonus Task

There is a way to avoid having to type all of these commands manually. You can use Git inside RStudio!

  1. Open RStudio and create a new project.
    • Select ‘Version Control’ and then ‘Git’.
    • Paste the URL of your project’s repository.
    • Select a folder where you want to store your project.
    • Click ‘Create Project’.
  2. You should see your project’s files on the bottom right panel.

Now, whenever you make changes to your files, you can use the Git tab to add, commit and push them to GitHub:

References

Chacon, Scott. 2014. Pro Git. Second edition. The Expert’s Voice in Computer Software Development. New York, NY: Apress. https://git-scm.com/book/en/v2.
GitHub. 2022. GitHub Cheatsheet.” Tutorials. GitHub Git Cheat Sheet - GitHub Cheatsheets. https://training.github.com/downloads/github-git-cheat-sheet/.