无法推送README.Rmd至GitHub及推送后Rmarkdown格式未正常渲染问题咨询
Let’s break down exactly what happened and how to fix it:
The Root Cause
When you run usethis::use_readme_rmd(), it sets up two critical pieces:
- A
README.Rmdfile (your editable source document) - A pre-commit Git hook that automatically renders
README.RmdtoREADME.mdbefore every commit.
GitHub only uses the README.md file to display a formatted preview—README.Rmd is treated as raw code because it’s a source file, not the final markdown output. By removing the pre-commit hook, you skipped the step that generates README.md, so only the unrendered Rmd file was pushed to GitHub. That’s why you see the raw code instead of a nice page.
Fixing the Immediate Issue
To get your README looking right on GitHub right now:
Generate the markdown file locally:
Run this command in your R console to convert yourREADME.RmdtoREADME.md:rmarkdown::render("README.Rmd")If you’re using RStudio, you can also just click the "Knit" button at the top of the
README.Rmdeditor pane.Commit and push both files:
In Git, stage bothREADME.Rmd(your editable source) andREADME.md(the rendered output), then commit and push. GitHub will now useREADME.mdto display the formatted page.
Preventing This From Happening Again
It’s smart to restore the pre-commit hook so you don’t have to manually render the README every time you make changes. Here’s how:
Re-add the usethis hook:
Runusethis::use_readme_rmd()again. When prompted if you want to overwrite your existingREADME.Rmd, select "No"—this will re-create the pre-commit hook without touching your modified content.Test the hook:
Make a tiny change toREADME.Rmd(like adding a space), then try to commit. The hook will automatically runrmarkdown::render()for you, updatingREADME.mdbefore the commit goes through. This ensures your source and rendered files stay in sync every time you push.
A Quick Note on the Pre-Commit Hook
The original block you encountered was a safeguard: the hook noticed README.Rmd had changed but README.md hadn’t, so it stopped the commit to prevent you from pushing incomplete or outdated files. Removing it skips that check, but keeping it enabled is the best way to maintain consistency between your work and what’s displayed on GitHub.
内容的提问来源于stack exchange,提问作者JaFranke

