In this set of exercises, we clone and work on the GitHub or GitLab repository you have created in the previous session.

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…

For using GitLab you should also have enabled SSH authentication through creating a RSA key in the Git/SVN options in RStudio.

Exercise 1

After we’ve made sure that everything works, we can now clone and work on the repository we have created on GitHub or GitLab in the previous session. When doing this, you should also create a new RStudio project.
You can create a new version-controlled project that is connected to an existing GitHub or GitLab repository via the RStudio menu. If you need some further information, you can check out the New project, GitHub first section in Happy Git and GitHub for the useR.

Exercise 2

If everything has worked, a new instance of RStudio should have opened with the working directory set to the location of your new 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). If you want to, you can also edit the R Markdown file(s) in your repository/project.

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 or untracked.

Exercise 4

After staging your changes, let’s create a commit and push that to the remote repository.
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/GitLab repository (while being logged in) and edit the README file in the browser (again, just add, remove, or edit a few words). How you edit a file depends on the platform:

On GitHub: You can edit the README via the small pen icon next displayed above the content of your README file.

On GitLab: Click on the name of the file you want to edit (in this case this should be README.md). Next, choose and click “Edit” from the blue dropdown menu shown next to the file name.

Once you have edited the file (and committed the changes directly on GitHub/GitLab), you can pull the changes to your local project.
Remember that if you edit a file directly via the GitHub or GitLab web interface, you also need to make a commit (and add a commit message). You can do the pull operation via the respective icon in the RStudio GUI.