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…
Git
via
RStudioHTTPS
for GitHubSome 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).
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.
You can create a new RStudio project in an existing directory via File -> New Project -> Existing Directory. As we will start working on the project right away, also check “Open in new session”.
If you have initialized Git
in that directory, the
Git
tab should be visible in the newly opened
RStudio instance (ideally, all files that you want to be
tracked should have been added and committed).
usethis::use_github(private = TRUE)
in
R
/RStudio (but you can also go
through the steps manually).
Git
tab. To make extra sure that
everything worked, let’s check the Git
status of our
project via the Terminal
in RStudio.
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).
git status
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.
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 (??).
You can stage changed files in the RStudio GUI by checking
the boxes in the Staged column in the Git
tab.
data
files/folder.
After staging the changes, simply click on the Commit button
in the Git
tab in RStudio, write a commit message
in the menu that opens up, and then click the Push button in
the same menu.
.gitignore
or you can store the data in a
different folder outside the project directory.
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).Git
tab in RStudio to update your
local project.