GitHub relative internal repository links in PULL_REQUEST_TEMPLATE.md
Asked Answered
G

2

13

Using a relative link as directed (https://help.github.com/articles/about-readmes/#relative-links-and-image-paths-in-readme-files) in a PULL_REQUEST_TEMPLATE.md does not relatively link correctly.

When viewed in an actual PR:

  • [CONTRIBUTING.md](/.github/CONTRIBUTING.md)

routes to: https://github.com/.github/CONTRIBUTING.md.

  • [CONTRIBUTING.md](.github/CONTRIBUTING.md)
  • [CONTRIBUTING.md](./.github/CONTRIBUTING.md)

route to: https://github.com/owner/repo/compare/.github/CONTRIBUTING.md

instead of https://github.com/owner/repo/.github/CONTRIBUTING.md.

Changing to ../ to go up a level would work for PRs, but would break the link when viewed in the GitHub UI.

Clicking the link as viewed on GitHub works: https://github.com/fs-webdev/fs-dialog/blob/master/.github/PULL_REQUEST_TEMPLATE.md, just not inside a PR.

(I feel like this used to work in 2017)

What is the correct way to have the relative link function as expected in both cases?

Gautama answered 12/3, 2018 at 18:59 Comment(3)
Relative links never start with a /. Try removing the / at the start of the link. In fact the linked documentation suggests ./ (the dot is before the slash not after) while you have /.Laundry
Removing the leading slash or adding a dot before it results in a GitHub comparison link: https://github.com/owner/repo/compare/.github/CONTRIBUTING.md, since that is the route a PR originates from.Gautama
I suspect you either need to do github/CONTRIBUTING.md or ./github/CONTRIBUTING.md.Laundry
H
4

Background

Unfortunately, the given implementation seems to consider only the current URL instead of the actual file path in the repository.

The same limitation can be noted when creating issues (through e.g.: https://github.com/owner/repo/issues/new):

[CONTRIBUTING.md](.github/CONTRIBUTING.md)

->

https://github.com/owner/repo/issues/.github/CONTRIBUTING.md

Workaround

I only managed to make the relative link work by specifying the full URL path (including the leading /):

[CONTRIBUTING.md](/owner/repo/.github/CONTRIBUTING.md)

->

https://github.com/owner/repo/.github/CONTRIBUTING.md

With that said, the abstraction can only go up to the URL host (i.e.: https://github.com).

Hester answered 4/11, 2019 at 21:14 Comment(1)
I had to use https://github.com/owner/repo/master/blob/.github/CONTRIBUTING.md or alternatively /owner/repo/master/blob/.github/CONTRIBUTING.md.Allonge
K
0

prefixing the markdown link with /OWNER/REPO_NAME/blob/main/ did the job and also linking sections - via #section-name works in that way :)

Keelboat answered 18/7, 2024 at 8:46 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.