Github is one of web-based hosting services for sharing and collaborating with code and data.
It all depends on your needs and preferences. Each are pretty similar.
We’re going to publish a folder to Github because it offers free hosting to open-source software projects.
It’s already where most R packages are hosted when they’re being developed.
If you’re using two-factor authentication in Github, you’ll need to go through some more steps for generating an SSH key to connect. This shouldn’t concern you if you’re using Github after just creating a new account.
Go to Github.com and create a new account if you haven’t yet. Use the same username and email address that you set up with your git global option.
For this example, we’re going to upload our folder of chunks that we created in the Publishing chapter.
In Github, create a new public repository called “chunks”.
Do NOT check “Initialize with README”. You want a blank repository.
This will create a new repository page, which needs to be synchronized with the local repository we’re about to create.
Create a folder somewhere (Remember good workflow. Maybe move it to your Documents folder or a new folder for Projects?) and also call it “chunks”.
Copy and paste the files, including 01_chunk.html and 01_chunk.rmd files into that “chunks” folder.
Open up your CMD/terminal and navigate to the folder.
For me, that would look like:
Type in the git commands we learned before to initialize, add, and commit.
git init git add . git commit -m "first commit"
Now we need to connect this repository on the local computer to the repository on Github.
The lines were provided when you created the repository on Github:
Type the equivalent of that into your terminal/cmd:
git remote add origin email@example.com:YOURUSERNAME/chunks.git git push -u origin master
Refresh your Github repo and all your files should be there:
Now you can get those HTML files hosted.
github.io is the address for hosted files. Can you spot what to swap?
First we need to set up Github to host the files.
After uploading your repo, click on Settings on the top right.
Scroll down to the GitHub Pages section of Settings.
Change the Source from
master branch and click save.
For future projects, you can organize your files so that all output HTML are stored in a
docs folder. Then the option
master branch\docs will host those files and ignore everything in the root folder.
Now go to https://YOURUSERNAME.github.io/chunks/06_chunk.html and you should have your hosted file!
What if you get some new data and wanted to update this?
And that is that!
With this published repo, you’re now part of the reproducible journalism community.
Last thing we’ll go over are some tips and best practices.
© Copyright 2018, Andrew Ba Tran
© Copyright 2018, Andrew Tran