Sub topic 15
Where GitHub looks for a README
This chapter assumes you can browse a repository and know that a README is a file written in Markdown. It covers which file GitHub picks, where it shows that file, and what that means for relative links.
The lookup order
GitHub shows a README on a repository's home page. If several exist, it picks the first one it finds in this order:
- The
.githubdirectory - The repository root
- The
docsdirectory
The file name must start with README, in capital letters. README.md is the usual choice. GitHub also renders other formats, such as README.rst, but only Markdown is covered here.
A common surprise
Suppose a repository has two files, README.md in the root and .github/README.md. Visitors see the .github one, because it is checked first. People often edit the root file and wonder why nothing changes. If a change does not appear, check for a second README higher in the lookup order.
my-project/
├── .github/
│ └── README.md <- shown on the home page (checked first)
├── docs/
│ └── README.md <- shown only when browsing docs/
├── README.md <- ignored on the home page here
└── src/READMEs in subdirectories
Each directory can have its own README. GitHub displays it below the file list when someone opens that directory. This works well for a docs/ or packages/api/ folder that needs its own explanation. The lookup order above applies only to the repository home page.
Special profile READMEs
Two repository names get special treatment.
| Repository | README location | Where it appears |
|---|---|---|
| `USERNAME/USERNAME` (public) | Root of the repository | Your personal profile page |
| `ORG/.github` | `profile/README.md` | The organization's profile page |
The user profile repository must have the same name as your username, and it must be public.
Relative links follow the file
A relative link is resolved from the folder that contains the README, not from the repository root. If you move the README from the root into .github, a link such as CONTRIBUTING.md points to .github/CONTRIBUTING.md. Check your links after any move. Use ../ to go up a level:
See [CONTRIBUTING.md](../CONTRIBUTING.md) for the guidelines.Choosing a location
- Use the root for most projects. It is the first place people look, and it also works in other tools that browse the files.
- Use
.githubwhen you want to keep the root uncluttered. - Use
docsonly if your documentation is already organized there.
Keep one README per location, and avoid having a second one in a higher-priority folder by accident.
Exercise
A repository has README.md in the root and another README.md in docs/. Which one appears on the home page, and which one appears when you open the docs folder?
Show answer
The root README appears on the home page, because the root is checked before docs. Opening the docs folder shows docs/README.md below its file list.