Chapter 4 Github

To quote from wikipedia, “Github is a Web-based Git version control repository hosting service. It is mostly used for computer code.”— and I would add, many other things.

The purpose of this chapter is to describe how Github can be used to serve your web-book (compiled using bookdown), and to share the source code so that others can duplicate and modify your book, or so that others can contribute content to your existing book.

4.1 Getting Started

4.1.1 Make an account with Github

To get started with Github you need to create a free account. You should see a sign up option on the main page.

Your account now consists of your profile page (where you can add information about yourself), and an empty list of repositories. Repositories are Github file folders. They can be purely cloud-based; for example, you can create a repository then add files to it through the web-based interface. You can also create a copy of each repository on your local computer, make changes to the repository on your local computer, and then merge those changes with the online repository.

4.1.2 Install Github Desktop

Github has provided a free and convenient tool for using your local computer to interface with the web-based version of Github. To use the tool, download and install the desktop app for Github. Once the app is installed, make sure that you connect it to your Github account so that you can access repositories that you create.

4.2 Repository workflow

We will use the following workflow:

  1. Create a new empty repository on the Github Website
  2. Clone the repository to your local computer
  3. Add files to the repo on your local computer (work locally)
  4. Merge the files back to the Github Website (share final versions)

4.3 Creating a new repository on Github.com

  1. Log in to Github.com
  2. In the top right corner of the page, click the “+” icon
  3. Choose new repository
  4. Give it a short name
  5. You have a few other options that you can revisit later
  6. Click create repository

4.4 Cloning a copy on your computer

  1. Open the Github desktop app
  2. Login in to your Github account
  3. Choose the clone repository option
  4. Find the name of the repository you created on Github and select it. Github Desktop will now download the contents of the repository and save it locally (in the file folder of your choice) on your computer

4.5 Make changes to the repository

  1. If you are on a mac, choose “show in finder”.
  2. You can now edit any of the files locally

4.6 Update the online github repository

  1. Any time you change a file, git will track all of the changes that you make
  2. To submit changes, choose the commit button
  3. All of your changes will now be uploaded to the online repository.