Chapter 3 Get your GitBook

To get your GitBook, you should follow these steps:

  1. Go to https://github.com/cjvanlissa/gitbook-demo
  2. In the top right of the page, click Fork.
    This will copy my gitbook-demo repository to your GitHub account.
  3. My repository is now copied to your account. It is a template repository, which means that you can create a new repository based on this one.
  4. Create a new repository for your own GitBook. Create one for a course you’ve been wanting to update. In the top-right corner of the GitHub website, click the + icon, and select “New repository”:
  5. In the dialog, select the gitbook-demo as “Repository template”, and give the repository an appropriate name for your course. Then, press Create repository:
  6. Now, go back to Rstudio on your computer. In Rstudio, click File > New Project. A dialog will open. If you set up Rstudio with Git correctly, the dialog should have an option to create a new project from Version control. Click it:
  7. In the next dialog window, you should copy the URL of the GitHub repository you created in Step 5, like so:
  8. Now, in Rstudio, you can open files for editing and create new files (explained in the next Chapter). Open files by clicking them in the Files editor (usually in the bottom right of Rstudio):
  9. After you make a change, it will show up in the Git tab (usually in the top right of Rstudio). You must Commit the change locally, and then Push the change to GitHub to update your repo. To Commit, select the file and click the Commit button. Write a short message to describe the changes you made, then click the Commit button again. Now, press Push to send your commits to GitHub.
  10. To render your book as a GitBook, you must “Build” it. In the top-right panel of Rstudio, you see a “Build” tab. In this tab, simply click the “Build Book” button to build your book. You should see a lot of rendering messages, until a window pops up with your brand new GitBook. If you get errors at this stage, you probably made a mistake in preparing your system (see the previous Chapter).
  11. Building the book generated a lot of new files in the ./docs directory. This directory contains the website files for your GitBook. Open the Git tab again, verify that the ./docs directory is listed, and Commit and Push all of these new files as described in Step 9.
  12. There is only one last remaining task: To publish your GitBook on GitHub pages. Once you do this, any change to the ./docs folder that you push to GitHub will lead to an immediate update of your GitBook website. Go back to the GitHub page for your Repository. Click on the Settings tab on the top right of the page:
  13. On the Settings page, scroll all the way down until you reach a section called GitHub Pages. There, under the “Source” heading, click the word None, and select master branch /docs folder. When you select it, the page will update, and if you scroll back down to the GitHub Pages section, you will see the URL where your GitBook is published. The first time, it will take a few minutes for your GitBook to come online. When you publish updates to the GitBook however (simply by following Step 11 again), the update will be near-instantaneous. The Pages section should now look like this (and that is hopefully the link where you found this book):