96

I have a public Git repository on Bitbucket. I want to link the latest version of a Read-Me file. Here's the link to a revision/commit:

https://bitbucket.org/wordless/thofu-interpreter/raw/5bfc37864c5d/ThoFu%20Interpreter/ReadMe.txt

I tried to replace the revision number with tip and default, but it didn't work. Is there any way to get a permanent link to my latest files?

Thomas Uhrig
  • 30,811
  • 12
  • 60
  • 80

5 Answers5

104

Two ideas:

Use master in the url (this seems to work):

https://bitbucket.org/wordless/thofu-interpreter/raw/master/ThoFu%20Interpreter/ReadMe.txt

Another idea is to create a wiki page for your project, then use the wiki's functionality to link to the latest version of a file with this syntax:

<<file path/to/file [revision] [linenumber]>>

Just omit the revision and line number parameters, they are optional.

Then, refer to the wiki page everywhere else you'd like link to the read me file.

Daniel A.A. Pelsmaeker
  • 47,471
  • 20
  • 111
  • 157
Sunil D.
  • 17,983
  • 6
  • 53
  • 65
  • 11
    This also works linking to /src/ on bitbucket rather than raw https://bitbucket.org/user/repository/src/branch/path/file – here Mar 27 '14 at 05:03
  • @sunil-d Any idea how to that for private repo? When I click on raw url of a image in my private repo, it redirects to bytebucket.org & append a token so that it can be viewed publicly...like `https://bytebucket.org/$username/$repo/raw/$sha/$filename.jpg?token=$sometoken`. But the token is different for each file. Is there any way I can get/generate this type of token through bitbucket api? – Khurshid Alam Jan 21 '15 at 19:03
  • @KhurshidAlam I'm not sure how that might work. A quick google search pointed to possibly using their API to get an OAuth token, but I doubt that is the same token used here (who knows). Sorry I couldn't help any further! – Sunil D. Jan 21 '15 at 23:36
  • 3
    bitbucket.org/user/repo/`raw/master`/ReadMe.txt stopped working bitbucket.org/user/repo/`src/default`/ReadMe.txt works though – adam Jun 17 '15 at 05:09
  • The Creole syntax : `<>` doesn't work for README files. The README files on Bitbucket only support markdown file. – Shreyas Nov 16 '15 at 02:36
  • From your very Atlassian link, your "wiki to code" syntax "Links to a given file within the same project as the wiki. You cannot link to files that reside in repositories in other projects. The link syntax does not work with tags." – yPhil Jun 24 '16 at 12:59
  • @adam: `/master/` works for me, is your branch named "Default" instead of "master"? –  Apr 02 '18 at 15:07
  • official answer from atlassian: https://confluence.atlassian.com/bitbucket/hyperlinking-to-source-code-in-bitbucket-824476709.html – Neil Apr 21 '18 at 05:01
37

There is an easy workaround for this issue by updating your relative links to src/[branch_name]/path/to/file. Works like a charm for me.

Emil Lundberg
  • 7,268
  • 6
  • 37
  • 53
a-fro
  • 481
  • 4
  • 4
13

The canonical way to add a link to a file in your repository using Markdown (the default for Readme files and Wiki pages) is by linking to the relative path of the file.

For example, if I had a structure like so:

<repo root>
|-- my-file.txt
|    
|-- my-dir 
|    |-- my-other-file

I'd be able to link to them as follows:

[my-file](my-file.txt)
[my-dir](my-dir)
[some-other-file](my-dir/some-other-file)

Bitbucket will then automatically link to the file at the current branch that you are viewing the file at. If you're viewing the Readme file in the overview that will mean the default branch (usually 'master').

JVDL
  • 1,157
  • 9
  • 16
3

I am using master like this for the last zip file of the code :

https://bitbucket.org/MIUSER/MIREPO/get/master.zip

Where MIUSER is my user and MIREPO is the name of my app.

Hope that this works :D.

CTala
  • 315
  • 4
  • 13
3

Here are working links:

RAW:

https://bitbucket.org/wordless/thofu-interpreter/raw/HEAD/TODO.txt?at=master&fileviewer=file-view-default

Source:

https://bitbucket.org/wordless/thofu-interpreter/src/HEAD/TODO.txt?at=master&fileviewer=file-view-default
Community
  • 1
  • 1
bjorkblom
  • 1,849
  • 3
  • 21
  • 31