So… how does one get their blog post on here? That’s an excellent question and I’m so glad that you asked!
It’s quite easy, really. All you need to do is follow the so-simple-and-easy-to-implement steps below! Hooray!
Step 1: Fork the github repository
First thing’s first, you need to fork the git repo on which this site is hosted: https://github.com/rlbarter/Practical-Statistics. Go to this repository and in the top righthand corner, click the Fork button. This creates your own copy of the repo in your GitHub account.
Now, you need to copy the repo onto your local machine. Basically you will write the following code in the command line i.e. terminal (assuming that you’ve installed git at some point in your life):
git clone https://github.com/YOUR-USERNAME/Practical-Statistics
Notice that you want to clone your fork of the repo, not the original repo.
Next, create a new branch on your local machine (git checkout
is for switching branches and the -b
flag says to create a new branch).
You need to make your changes on this new branch.
git checkout -b NAME-OF-NEW-BRANCH
Now you should have all the files necessary.
Step 2: Write your blog post using R Markdown
Write your blog post in RStudio as an R Markdown file, and save your .Rmd
file in the /content/post
folder. You do not need to compile this file into html anywhere.
Any figures that you link to in your markdown file need to live in the static
folder. Where you put it in this folder is up to you (for example, for the anova blog post, I put all of the images in the static/img/anova
folder).
Once you’re done, add and commit your blog post:
git add FILENAME
git commit -m "A brief message about what files you're adding"
Step 3: Submit a pull request
Now that you’re all done adding things, you need to merge it into the website. You do this in two steps: you’ll push it to your GitHub repo and then submit a pull request, asking us to pull your changes into the website. First, push your changes to your repo:
git push origin NAME-OF-NEW-BRANCH
Now, navigate back to the original repo. At the top of the repo, the new branch will show up with a green Pull Request button - click it and submit the request.
Now, the maintainers will either merge your changes into the website, or may ask you to make modifications first. If the latter happens, follow this same process of commits and pushes, and they will automatically get added to your open pull request.
Advanced steps
If you would like to be able to render the website locally on your machine before submitting your post or any changes to the public version, you need to follow the instructions on the RStudio blogdown github page.
Basically, set your working directory to your cloned folder, install the blogdown package in R, and run blogdown::serve_site()
. The website should appear in the Viewer pane.
Divergence between the main repository and your fork
As the website gets updated, the main repo will change, but yours will not be automatically updated. To keep yours in sync, you need to set up access to the main repo:
git remote add upstream https://github.com/rlbarter/Practical-Statistics
Before, you did pushes and pulls from your fork, which was called origin
.
upstream
refers to the original repo.
You could name these whatever you wanted, but origin
and upstream
are the conventions.
You can see where else you have push/pull access to by running git remote with the -v
flag:
git remote -v
Now to actually update your local clone and your fork on GitHub, you’d run
git checkout gh-pages
git pull upstream gh-pages
git push origin gh-pages
The steps here are pretty straightforward: make sure you’re on the right branch, pull from that branch in the main repo, and push the updated branch on your machine to your GitHub fork. You can do this for the master branch as well.
Deleting old branches
After you’re done making a pull request, you might want to get rid of old branches that have already been merged. You can see what branches you have by running
git branch -v
To delete a branch, first delete it locally and then delete the branch on your GitHub:
git branch -d OLD-BRANCH
git push origin :OLD-BRANCH