Search code examples
gitgithubmarkdownbitbucket

How can I link to a Markdown section of my Bitbucket README?


I'm trying to create a link to a section of the README file of my Bitbucket repository. The following works as expected on GitHub, but not on Bitbucket. What am I doing wrong?

## Navigation
[1. GIT To Work](#git)

... 

## 1. Git To Work - Working with git<a name="git"></a>
### What is git?

Solution

  • One peculiarity of Bitbucket's Markdown "flavour" is the way it names heading identifiers. If you inspect the HTML source of your Bitbucket README page (by default accessible at https://bitbucket.org/<username>/<reponame>), you'll see that the Markdown section

    ## 1. Git To Work - Wording with git
    

    translates to the following HTML heading element:

    <h2 id="markdown-header-1-git-to-work-working-with-git">1. Git To Work - Working with git</h2>
    

    Note that Bitbucket uses, as the value of the id attribute, a URL-friendly version of your heading, prefixed by markdown-header-. Therefore, you can create a link to the corresponding section, in your Markdown code, using

    [Link to Git](#markdown-header-1-git-to-work-working-with-git)