Skip to content

Linking content from a repository

If you need to link some content from a repository in some document for internal or public discussion, please keep in mind that content in a repository is always subject to change: files can be removed or renamed, or their content updated.

For example if we mention the file https://github.com/nestauk/nesta/blob/dev/setup.py in the dev branch, after a while it could be removed or renamed, or its content be updated.

For this reasons it's generally best referring to content in tags.

Linking to a file in a specific commit

To refer to the above file version in a specific commit, once you have navigated to its page on github, please use the three dots menu and choose Copy permalink:

You should get a URL like https://github.com/nestauk/nesta/blob/f4f62b55960b9e0a783ac2e9c8d11d6045eff5eb/setup.py.

Linking to a line in a file content in a specific commit

  • Head to https://github.com/nestauk/<reponame>
  • Click on the Code tab
  • Select a specific branch (say dev)
  • Click on Commits to see the history of that branch
  • Click on a particular commit
  • Find that file
  • Click on the line number on the left gutter in that particular file to refer to a specific line in a specific file. You should get something like https://github.com/nestauk/nesta/blob/dev/setup.py#L12 (notice the added #L12).

Linking to tagged content

Branches can be deleted after merging them into the parent branch, so sometimes even linking to a particular commit in a "volatile" branch isn't enough.

Whenever it is desirable to avoid breaking links in external publications, best referring to tags.

The procedure is the same as above but we have to choose a tag instead of a normal branch.

If we select a tag named 0.4

and link line 5 of setup.py, we get: https://github.com/nestauk/nesta/blob/0.4/setup.py#L5