Requirements to follow this post
The following procedure requires some credential setup for GitHub on your end. There are several routes you can go:
- Set up the GitHub repo first. It my sound counter-intuitive, but the easiest way to get your work onto GitHub is to initiate a GitHub repo first, then use RStudio to start working in a synced local copy. This approach is described in Happy Git’s workflows New project, GitHub first and Existing project, GitHub first.
- Command line Git. I will use this approach to add a remote repository post hoc. This is described detailed in the Happy Git workflow Existing project, GitHub last.
Why using Git and GitHub?
After initializing a new Quarto blog I will create the initial (first) Git commit, initialize a GitHub repo, and push the content of the initial commit into the new repository.
There are several reasons to use Git:
- A Git repository (or repo) holds all the project files and their entire revision history. It is therefore not only easier to track changes but also to restore a previous version if necessary. (See the nice introduction)
- GitHub is an online platform to store and manage your content (code but also text and other resources), as well as track changes to it. It facilitates collaborations with your team but also with other (unknown) people.
Procedure for using Git
In the previous blog post, we have already initialized the Quarto weblog, including Git support, by checking the appropriate check box.
- To see all the changes you have made so far, click on the Git tab at the top right pane of RStudio. You should see a picture similar to the following one.
- After selecting all files and checking them (checking a single file of a group of selected files checks all selected files), the Git window shows all files seen above but also the files inside folders that are now prepared for the next Git commit.
- After clicking on the “Commit” tab (or using the shortcut
CTRL-ALT-M
) a window opens for writing the commit message. Write short notes using a commando language. For example a commit text for the mainindex.qmd
file could be: “change title-block-banner to true”.
It is usual to start the commit messages with “initial commit”. I had erroneously used “first commit” in the screenshot.
- After clicking the
Commit
button, RStudio presents a window with the results of the action:
Closing both windows will end the Git procedure to the local repository.
Procedure for initializing a GitHub repo
Next create a GitHub repo with all the locally committed content. I am using here the {usethis} package because it automates all the necessary steps. However, — as I mentioned above — there are several requirements before you can create and connect a GitHub repo. With Happy Git and GitHub for the useR you should read and learn how to connect an RStudio project to GitHub under different conditions. In this case, I have applied Chapter 17, “Existing project, GitHub last”.
- Write
usethis::use_github()
into the console window of the RStudio window (lower left pane). After return your console will display the following lines:
The screenshot above shows the different actions for the usethis::use_github()
command. In the last step, the newly generated and updated repository on GitHub was opened.
Summary
This post shows how to initialize Git and GitHub using RStudio after crating of the brand-new Quarto blog:
- Commit all the files generated automatically after launching the Quarto blog (as described in Initializing a Quarto Blog with RStudio) to the local Git repository.
- Initializing a remote GitHub repository, connecting the local repo with it, and connecting it with the local repo.