2

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?

David Grayson
  • 84,103
  • 24
  • 152
  • 189
  • If I remember correctly your file tree is under `/test_github` but all your wiki/README files are under `/test_github/blob/master`. So from your README file the relative path to access your root folder would be `../../` – GabrielOshiro Sep 10 '16 at 12:48
  • https://github.com/gabrieloshiro/github-markdown-playground – GabrielOshiro Sep 10 '16 at 12:50
  • Gabriel: Thanks, I might have to do it that way, but I was hoping for something better because when I am visiting https://github.com/gabrieloshiro/github-markdown-playground/blob/1c378d5/README.md and click on your first link, the URL loses the commit number and just goes to display the HEAD commit. – David Grayson Sep 11 '16 at 05:32
  • Ohhhhh I see now.... – GabrielOshiro Sep 12 '16 at 15:02
  • http://stackoverflow.com/questions/7653483/github-relative-link-in-markdown-file ? – GabrielOshiro Sep 12 '16 at 15:04
  • Doesn't answer my question. – David Grayson Sep 12 '16 at 16:56
  • :-( sorry... good question though... – GabrielOshiro Sep 12 '16 at 19:23
  • You just need to provide filename and it seems a trick with "../" works as you need, eg: `Make sure to read [main README](../README.md) first, pls.` But I'm not able to link the main folder though. Strange. – Patrycja K Jan 04 '18 at 16:03

1 Answers1

0

like this.

<a href="../../tree/master">link to top</a>