Blogdown tutorial (Part 2)

Creating a Github repository

Update 2021-05-19: Even if some screenshots might have changed slightly, this part of the tutorial is still up to date. But there are now many other resources with the same content available.

Especially I would like to recommend Up & running with blogdown in 2021 by Allison Hill, co-author of the blogdown book. There is a small part at the end to the integration into GitHub.

R User now can use the helpful package usethis with information how to get Git(Hub) Credentials and with Happy Git and GitHub for the useR there is also a gentle introduction to Git & GitHub.

In part 1 we have installed the hugo-academic theme on top of R, RStudio and blogdown. We will continue the installation process with creating a remote GitHub repository.

Create a GitHub repo

In case you do not have a GitHub account, sign up for it. When you have finished the registration process click the button “Start a project”. If you already have an account click at “New repository”.

Creating a new GitHub repository.
Creating a new GitHub repository.

Name your GitHub repo

Both actions (“Start a project” and “New repository”) opens up a window where you can name your new repository. Leave all the other options empty resp. as they are and click the green button “Create repository”.

Name your new GitHub repository.
Name your new GitHub repository.

Quick Setup

The last click brings you to a “Quick setup” page with several options. As there already exist a repository with our hugo-academic files, we copy the two lines in the third option: “push an existing repository from the command line”.

Quick setup: push an exiting repository from the command line.
Quick setup: push an exiting repository from the command line.

Shell commands: git init

But before we can paste these two lines into the terminal in order to link our local with the remote GitHub repository we need to download Git and install it. The best description I know of the installation procedure and its integration with RStudio is by Hadley Wickham in chapter 13 of his book about R Packages. There is a online version available. Read the two sections Initial set up and Create a local Git repository. For the mentioned shell commands you can use the Terminal tab of RStudio in the left lower pane.

Use for the shell command the new terminal tab of RStudio.
Use for the shell command the new terminal tab of RStudio.

Git tab in RStudio

5After the shell command git init the local repository is under version control. After you have restarted RStudio you will now see new tabs in the RStudio panes. Click in the Git tab in the upper right pane. This reveals a bunch of folder and some files. The yellow boxes with the question marks under the status column indicate that these file are not yet under version control.

Folders and files which are not under version control.
Folders and files which are not under version control.

Add files under version control

To bring these folders and files under version control you have to select all of them and click in one of the check boxes under the column “Staged”. You will see now a lot more files as all the files under the still untracked folders are explicitly shown. The A indicates that these files are new (are just added) to the repository.

New (Added) files to be set under version control.
New (Added) files to be set under version control.

Initial commit

A click in the Commit tab opens up a new window where you must write a message. This is necessary so that all collaborators (including the future-you!) remembers what was the change about. This first (e.g.initial) commit will bring all the files under version control.

The initial commit brings many files under version control.
The initial commit brings many files under version control.

Success message

After sending your message by clicking the Commit button you will see a list of all the committed files which are now in the local repository under version control. You can close this window and we can finally add our two lines copied from the GitHub page.

Files are successfully committed.
Files are successfully committed.

Connect local with remote repo

Insert the two copied lines from the GitHub repository into the Terminal tab (red arrow). The first line will establish the connection between the local and the remote repository. The second line will push all the committed local files to the GitHub repository.Depending of you internet connection and how many data has to be transferred this can take a couple of seconds (blue arrow).

Connecting local Git with remote GitHub repository and pushing the initial commit.
Connecting local Git with remote GitHub repository and pushing the initial commit.

After this second step we are going to to get a live preview of your website.

Edit this page

Peter Baumgartner
Peter Baumgartner
Retired Professor of Technology Enhanced Learning (TEL)

My research interests include eLearning, educational technology, educational design, open science and data science education.


Related