16

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?
jub0bs
  • 54,300
  • 24
  • 162
  • 166
Cruzito
  • 331
  • 1
  • 3
  • 10
  • 4
    I'm voting to close this question as off-topic because it asks for user support for a specific site; see http://meta.stackoverflow.com/questions/255745/why-were-not-customer-support-for-your-favorite-company . – Marcus Müller Mar 22 '15 at 11:06
  • 3
    Closing this question seems unfair. This [one about GitHub wikis](http://stackoverflow.com/questions/26584788/change-font-in-github-flavored-markdown-for-table) remains open. – jub0bs Mar 23 '15 at 15:41

2 Answers2

26

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)
jub0bs
  • 54,300
  • 24
  • 162
  • 166
  • 13
    My Bitbucket doesn't generate "id" attribute for headers. It's just simply "

    YAML configuration

    ". How can I link to it? (Atlassian Bitbucket v5.8.0)
    – emeraldhieu Mar 16 '18 at 04:32
  • 4
    Our internal BitBucket does not auto generate ID's on h2's either. – Frank Stallone III Mar 31 '20 at 13:45
  • 1
    Just used this answer to reach the probably more up-to-date solution - for me I used `[Link to Git](#markdown-header-git-to-work-working-with-git)` - prefixing with `markdown-header` (and not `markdown-header-1` or any number at all). Thanks! – yair Nov 16 '20 at 12:04
  • 2
    On Bitbucket Server, there is neither a name or id generated on header tags and it will strip id attributes, so you're forced to use `name` and link to the name specified. – Maximilian Burszley Dec 15 '20 at 16:29
  • @MaximilianBurszley My answer is getting old, now. Things might have changed. Feel free to update it or, better, post your own answer. – jub0bs Dec 15 '20 at 18:32
  • 1
    That's fair. I was just adding nuance as I'm pretty sure Bitbucket Cloud works as your answer provides. – Maximilian Burszley Dec 15 '20 at 18:38
7

Anchor links work on my Bitbucket server but don't work in VS Code unfortunately.

[link](#section) 

## Code and Syntax highlighting  <a name="section"></a>