In this set of exercises, you can continue to work on the Git directory you created in the previous session (we’ll be following the Existing project, GitHub last path). Alternatively (e.g., if you encounter any issues), you can also follow the New project, GitHub first approach and start from a new GitHub repository. Regardless of which option you choose, Exercises 2 to 5 should work the same.

In order to do the following exercises, you should have gone through the steps described in the setup information for the workshop. Specifically, you should…

Some important notes for these exercises:

For adding some R content to your repository, you can either use or create your own scripts or use/build upon the demo_script.R file from the exercises folder.

NB: Keep in mind that you should never put real research data on GitHub. While the data we have provided for use in this workshop are synthetic, we still recommend that you do not upload the data to the repositories you create (also to establish “data protection”-compatible practices for yourself).

Exercise 1

After you’ve made sure that everything works, create a new RStudio project in the existing directory with Git initialized that you should have created yesterday. Next, create a GitHub repository and connect it to your local project.

You first need to create a local RStudio project and associate it with the existing directory you created before (Git should be initialized there and, ideally, all files that you want to be tracked and connect to the remote GitHub repository should already be staged and committed). Next, you need to create a GitHub repository and connect it to your local project. If you need some help (or further information), check the Existing project, GitHub last section in Happy Git and GitHub for the useR.

If you encounter any issues that you cannot solve in the setup, you can also follow the New project, GitHub first route and create a new (and empty) project. The following exercises will essentially work the same either way.

Exercise 2

If everything has worked, a new instance of RStudio should have opened with the working directory set to the location of your project, the files included in the project folder visible in the Files tab, and an active Git tab. To make extra sure that everything worked, let’s check the Git status of our project via the Terminal in RStudio.
You may want to check which shell the Terminal in RStudio uses via Tools -> Global Options -> Terminal. If you use Windows, you should choose Git Bash (which you should have installed with Git for Windows).

Exercise 3

Now that the project is set up and in sync with the remote repository, we can start working on it. Modify the README file (just add, remove or edit a few words).

Also add (stage & commit) an R script to the repository. You can use the demo_script.R that we have created (and modify it) or use/create your own script.

After modifying the file(s), save the changes (via the Save icon in the RStudio menu or the keyboard shortcut your OS uses for saving files) and stage them in Git.

You can use the RStudio GUI for staging changes (for modified or added files). As a reminder: When you modify existing files and/or create new ones and save the changes, these should be displayed in the Git tab in RStudio and their status will be indicated as modified (M) or untracked (??).

Remember that you should not upload research data to GitHub.

Exercise 4

After staging your changes, let’s create a commit and push that to the remote repository. Again, remember not to commit and push any research data.
You can do both (committing and pushing) via the RStudio GUI. Remember to write a meaningful commit message.

Exercise 5

As a final exercise for this session, let’s do the opposite of pushing and pull changes from the remote repository to your local project. Before we can do this, we first need to make some edits in the remote repository. Go to the website of your remote GitHub repository (while being logged in) and edit the README file in the browser (again, just add, remove, or edit a few words). Once you have edited the file (and committed the changes directly on GitHub), pull the changes to your local project.

You can edit the README via the small pen icon next displayed above the content of your README file on the website of your GitHub repository.

Remember that if you edit a file directly via the GitHub web interface, you also need to make a commit (and add a commit message).