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:
- Create a new empty repository on the Github Website
- Clone the repository to your local computer
- Add files to the repo on your local computer (work locally)
- Merge the files back to the Github Website (share final versions)
4.3 Creating a new repository on Github.com
- Log in to Github.com
- In the top right corner of the page, click the “+” icon
- Choose new repository
- Give it a short name
- You have a few other options that you can revisit later
- Click create repository
4.4 Cloning a copy on your computer
- Open the Github desktop app
- Login in to your Github account
- Choose the clone repository option
- 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
- If you are on a mac, choose “show in finder”.
- You can now edit any of the files locally
4.6 Update the online github repository
- Any time you change a file, git will track all of the changes that you make
- To submit changes, choose the commit button
- All of your changes will now be uploaded to the online repository.