Why Relative Links in a GitHub README Break After Files Move

Diagnose broken GitHub README relative links after files move, and check paths, anchors, branches, forks, local previews, and documentation sites.

Published
Reading time
5 min read
Why Relative Links in a GitHub README Break After Files Move
On this page

A README link can break when either the README or its target moves. The link text may still look right, but its path is interpreted relative to the README’s directory—not necessarily the repository root. This guide shows how to recalculate those paths and review them in GitHub, local previews, documentation sites, and forks.

Key Takeaways

  • A relative link starts from the directory containing the Markdown file.
  • Moving a README changes the starting point; moving its target changes the destination. Either can require a link update.
  • GitHub, a local preview, and a published documentation site can use different rendering and URL rules. Test each surface you support.
  • Check branch-specific links and heading anchors as well as file paths.

Consider this example repository layout:

repository/
├── README.md
├── assets/
│   └── logo.svg
└── docs/
    ├── README.md
    └── guides/
        └── setup.md

In the root README.md, a link to the setup guide starts at the repository root:

[Setup guide](docs/guides/setup.md)

In docs/README.md, the starting directory is docs/, so the link is shorter:

[Setup guide](guides/setup.md)

The nested README needs .. to reach the root-level assets directory:

[Logo](../assets/logo.svg)

Each .. moves up one directory. A path that works in one README cannot necessarily be copied into another unchanged.

Advertisement

For each broken link, identify the directory containing the Markdown file, then walk the link path from there. Compare the result with the target’s actual location and capitalization.

If the target moved

Suppose setup.md moved from docs/setup.md to docs/guides/setup.md. A link in the root README must change from docs/setup.md to docs/guides/setup.md. Also search other Markdown files for links to the old location; updating only the root README can leave other inbound links broken.

If the README moved

Suppose the README itself moved from the root to docs/. Its old link to assets/logo.svg now points under docs/. Change it to ../assets/logo.svg to reach the root-level file.

Review links inside any moved Markdown file, too. For example, if docs/setup.md contained [Logo](../assets/logo.svg), the same link in docs/guides/setup.md needs to become [Logo](../../assets/logo.svg).

A link can include a fragment after the file path, such as:

[Setup prerequisites](docs/guides/setup.md#prerequisites)

Check the path and the fragment separately: the file may open successfully while the fragment no longer identifies the intended heading.

Compare GitHub, local previews, and documentation sites

On GitHub, relative repository links in a rendered README are generally interpreted in the context of the Markdown file and the repository view. Open the README on the intended branch or commit and click the link; a URL copied from a different branch may not represent what readers see. GitHub’s exact behavior can depend on the view, so verify the views your readers use.

A local Markdown preview may resolve links against files on disk or apply its own preview rules. A documentation generator may transform Markdown files into pages, rewrite links, assign heading IDs differently, or publish pages at URLs that do not mirror source paths. A link that works in one environment is therefore not proof that it works in another.

For a practical comparison:

  1. Open the README in the GitHub branch intended for release and click each changed link.
  2. Open the same file in the local preview your contributors use; check both navigation and heading fragments.
  3. If you publish a documentation site, build or preview it with your project’s normal tooling and test the generated page there.
  4. Where behavior differs, use the documentation generator’s supported linking conventions rather than assuming GitHub’s source-file paths will be rewritten correctly.

A leading slash is not a reliable shortcut to a repository root: in a web URL, it is resolved from the site’s origin, and documentation generators may apply their own rules. Prefer an appropriate relative path or a deliberately chosen absolute URL, and test it in the intended environment.

Advertisement

Pre-release review checklist

  • Moved or renamed files: Search the repository for old paths, including image references and links in other READMEs. Check outgoing links inside moved files and confirm path capitalization.
  • Renamed branches: Search for absolute GitHub URLs that contain the old branch name. Update them where appropriate, then open the README on the release branch and check its relative links in that context.
  • Anchors: Click links to headings after heading edits or file moves. Check generated heading IDs on each published surface, especially when headings are duplicated or contain punctuation.
  • Forks: View the README in a fork on the branch being reviewed. Check whether links stay within that fork where intended; absolute links to the upstream repository may be intentional, but should not be accidental.
  • Other renderers: Test the local preview and generated documentation site if your project supports them. Record any intentional differences in contributor guidance.

Common Mistakes

  • Fixing only links to a moved file. Links inside the moved file may also need new paths.
  • Assuming a successful file open proves the anchor works. A page can load without navigating to the intended heading.
  • Assuming every renderer uses the same base URL or heading IDs. Check the actual GitHub and documentation-site views.
  • Using an absolute branch URL without reviewing its purpose. It can point a fork’s readers to upstream or refer to an outdated branch.

Best Practices

Keep links relative when they should follow the repository or fork, and use absolute URLs deliberately when readers should go to a specific external or upstream destination. Review link changes alongside file moves, then verify them in the rendered views readers will actually use.

GitHub’s official documentation for README and repository-relative links should be consulted for current platform-specific behavior. It was not accessible for review in this article, and the examples have not been executed or checked in a live repository.

Conclusion

When a README link breaks after a move, recalculate it from the Markdown file’s new directory, then check the target and any fragment. Finish by testing the rendered link on the relevant GitHub branch and any local or published documentation surfaces.

What would your domain sell for?

A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.