Show a GitHub file from a branch, tag or commit in Confluence

To show a GitHub file from a branch, tag or commit in Confluence, open the file on github.com at that branch, tag or commit, copy the link and paste it into the page or into the picker's search box. The macro reads the ref from the link. The picker's own browsing always uses the repository's default branch.


#Before you start

  • You can edit the Confluence page.

  • You know which branch, tag or commit you want. A tag or commit keeps the file fixed; a branch follows its latest commit.


#Steps

  1. On github.com, open the file and use the branch menu to switch to the branch or tag you want. For a fixed version, open the file from a commit instead.

  2. Copy the address. It looks like https://github.com/owner/repo/blob/v2.1.0/docs/setup.md.

  3. Edit the Confluence page and paste the link on an empty line. It becomes the Github file (Capable) macro.

  4. To change an existing macro instead, open its configuration, paste the link into Search repositories or paste URL..., press Enter and select Add to page.

  5. Publish the page.


#What happens next

The macro header shows the ref in brackets after the path, for example (v2.1.0). Nothing is shown for main. A branch keeps moving as people commit; a tag or commit link shows the same content until you change the macro.


#If it does not work



The version you meant, every time.