Search code examples
githubgithub-flavored-markdown

How to link to the top-level directory of a GitHub repository


Suppose I am writing a README.md file for a subdirectory in a GitHub repository using GitHub-flavored Markdown. How can I can construct a link that goes to the top-level directory of my repository, while preserving the branch or commit that the user is currently viewing, and not requiring me to hardcode the name or owner of the repository?

Relatives links in READMEs are supposed to work on GitHub, and they do work for most files and directories in a repository, but I can't figure out how to link to the top-level directory of a repository.

I have a file in my test repository named subdir/README.md where I tried putting the following relative links:

[link to ../](../) - does not work

[link to ..](..) - does not work

[link to ./..](./..) - does not work

However, when these links are rendered, they all go to a single URL like https://github.com/DavidEGrayson/test_github/blob/master which returns a 404 page instead of redirecting to https://github.com/DavidEGrayson/test_github/tree/master.

I really want to be able to link to the top level of a repository because that is where the Download button is. So, how can I do it?


Solution

  • This appears to have been a bug in GitHub Markdown rendering that has since been fixed. I just checked your DavidEGrayson/test_github repository, both at the current HEAD as of this writing and at commit cf171fe and all three links that you marked as "not working" are all working fine for me right now.