Basic Git/GitHub Skills in RStudio

Learning Objectives
  • Learn how to use the Git GUI in RStudio
  • Practice 4 basic Git/GitHub skills: cloning, committing, push/pull

Prerequisites

Setting up Git

You should have gotten this done on Tuesday but if not here are the instructions

Before we can work with Git in the JupyterHub, we need to do some set up.

  1. Tell Git who you are and to store your credentials (GitHub login info)

Show me

Paste this into a terminal window:

git config --global user.email "<your email>"
git config --global user.name "<your name>"
git config --global pull.rebase false
git config --global credential.helper store
  1. Get a Personal Access Token from GitHub

Copy the token! You will need it in the next step.

Show me Note, one change to this video is that you need to specify that you want a classic token.

  1. Trigger Git to ask for your password (that personal access token)

You can do this by cloning a private repo. In the Terminal, issue this command

git clone https://github.com/Hackweek-ITCOocean/github_setup_check

It will ask for your GitHub username and password. At the password part, paste in the Personal Access Token.

Git tab

When the instructions say to use or open or click the Git tab,

The Key Skills

  • Skill 1: Create a blank repo on GitHub

  • Skill 2: Clone your GitHub repo to RStudio

  • Skill 3: Make some changes and commit those local changes

  • Skill 4: Push the changes to GitHub

  • Skill 1b: Copy someone else’s GitHub repository

Let’s see it done!

Skill 1: Create a blank repo on GitHub

  1. Click the + in the upper left from YOUR GitHub page.
  2. Give your repo the name Test and make sure it is public.
  3. Click new and check checkbox to add the Readme file and .gitignore
  4. Copy the URL of your new repo. It’s in the browser where you normally see a URL.

Show me

Skill 2: Clone your repo to the RStudio

In RStudio we do this by making a new project.

  1. Copy the URL of your repo. https://www.github.com/yourname/Test
  2. File > New Project > Version Control > Git
  3. Past in the URL of your repo from Step 1
  4. Check that it is being created in your Home directory which will be denoted ~ in the JupyterHub.
  5. Click Create.

Show me

Skill 3: Make some changes and commit your changes

This writes a note about what changes you have made. It also marks a ‘point’ in time that you can go back to if you need to.

  1. Make some changes to the README.md file in the Test repo.
  2. Click the Git tab, and stage the change(s) by checking the checkboxes next to the files listed.
  3. Click the Commit button.
  4. Add a commit comment, click commit.

Show me

Skill 4: Push changes to GitHub / Pull changes from GitHub

To push changes you committed in Skill #3

  1. From Git tab, click on the Green up arrow that says Push.

  2. To pull changes on GitHub that are not on your local computer:

  3. Make some changes directly on GitHub (not in RStudio)

  4. From Git tab, click on the down arrow that says Pull.

Show me

Pair-activity 1

In RStudio,

  1. Make a copy of README.md
  2. Rename it to .md
  3. Add some text.
  4. Stage and commit the added file.
  5. Push to GitHub.

Try before watching.

Show me in RStudioShow me in the shellShow me in jupyter-git

Pair-activity 2

All of this activity is in RStudio.

  1. Clone this repo https://github.com/Hackweek-ITCOocean/git-basics to RStudio and create a new project
  2. Navigate to the files in your new project, create a filed called to <yourname>.md. Use your actual name so the filename is different from everyone elses.
  3. Stage and then commit that new file.
  4. Push to GitHub.
  5. Make some more changes and push to GitHub.
  6. Pull in your partner’s (and everyone elses) changes

Show me in RStudioShow me in JupyterLab

Pair-activity 3

You can copy your own or other people’s repos1.

  1. In a browser, go to the GitHub repository https://github.com/RWorkflow-Workshops/Week5
  2. Copy its URL.
  3. Navigate to your GitHub page: click your icon in the upper right and then ‘your repositories’
  4. Click the + in top right and click import repository. Paste in the URL and give your repo a name.
  5. Use Skill #1 to clone your new repo to RStudio and create a new project

Footnotes

  1. This is different from forking. There is no connection to the original repository.↩︎