How to Share Code With Your Paper (and Get It Cited)

Before: "Code available at github.com/ourlab/analysis."

After: "Analysis code is archived at Zenodo (doi:10.5281/zenodo.XXXXXXX, v1.2, the version used for this paper) and developed at github.com/ourlab/analysis. The repository includes a README with run instructions, the environment specification, and a script that reproduces every table and figure from the deposited data."

The first version will break. Repositories get renamed, made private, force-pushed, or deleted when someone leaves. Worse, even if the link survives, nobody knows which commit produced the results in your paper, because the code kept changing after submission.

The second version is permanent, versioned, and citable. The difference between them is about forty minutes of work, once.

Why a repository link is not archiving

These are two different jobs and people conflate them constantly.

A code host — GitHub, GitLab — is for development. It is mutable by design: that is the point. It has no preservation commitment, and the organisation hosting it can disappear or change its terms.

An archive is for permanence. It takes a frozen snapshot, gives it a DOI, and commits to keeping it. Readers in 2035 can still get the exact bytes you used.

You want both, and they connect easily: GitHub integrates with Zenodo so that creating a release automatically deposits a snapshot and mints a DOI. Turn that on once and every tagged release is archived from then on. Software Heritage archives public repositories more broadly and is worth knowing about as a safety net, though a Zenodo DOI is what you cite.

Sharing code with a research paper: what reviewers actually need

Reviewers are not auditing your software engineering. They are asking one question: could someone establish that the numbers in this paper came from this analysis?

That makes four things necessary and almost everything else optional.

  1. The code that produced the results, not a cleaned-up rewrite. If you tidy it, re-run it and confirm the outputs still match before depositing.

  2. The environment. Language version and package versions, as a lock file, an environment YAML, or a container image. Code without an environment specification stops working within about two years, and the failure mode is silent: it runs and gives different numbers.

  3. A README with what the code does, how to run it, roughly how long it takes, and what data it expects.

  4. An entry point. One script a stranger can run. `make all`, `run_analysis.R`, `main.py` — anything, so long as it is obvious and it works from a clean checkout.

That is the whole requirement. Tests, continuous integration and documentation are good practice and nobody will reject your paper for lacking them.

How much documentation is enough

Enough that someone competent in your field, with your data, can reproduce your tables without emailing you.

In practice that means naming files for what they do, a comment at the top of each script saying what it takes and what it produces, and a line in the README mapping outputs to the paper: "Table 2 is produced by `03_models.R`". That mapping is the single most useful sentence you can write, and it takes thirty seconds.

What is not required: docstrings on every function, a documentation site, a tutorial. If you are building a tool others will use, those matter. For analysis code attached to a paper, they are the reason people never share anything.

What to do when you cannot share everything

Plenty of analysis code cannot be released as-is, and the common response — sharing nothing — is almost always worse than the alternatives.

The code depends on data you cannot share. Share the code anyway, with a small synthetic dataset of the same shape so a reader can run it end to end. Generating fake data with the right columns and plausible distributions takes an hour and converts an unrunnable repository into a demonstrable one.

Part of the pipeline is proprietary. Share the parts you own and state plainly where the boundary is. "Steps 1-3 use an internal preprocessing library we cannot release; the deposited code begins from the cleaned matrix, whose format is documented in the README" is honest and still useful.

The code is embarrassing. This is the real reason most of the time, and it is worth naming. Analysis code written under deadline is ugly everywhere, including in labs whose papers you admire. Reviewers are not grading style, and the alternative to ugly shared code is unverifiable results.

It depends on a cluster or specialist hardware. Share it with a note on what it ran on and roughly what it cost in compute. Someone with the right hardware can still use it, and someone without now knows why they cannot.

Containers, when they are worth it

A container image freezes the whole environment, which solves the dependency problem completely. It is also a larger artefact to build, store and explain.

My rule: a lock file or environment specification is enough for ordinary analyses in a mainstream language. Reach for a container when the stack is awkward — unusual system libraries, a compiled dependency that is painful to build, a pipeline spanning several languages. Deposit the recipe (the Dockerfile) as well as the image, since the recipe is what someone can read and adapt.

Licensing, briefly

Code with no licence is, legally, all rights reserved — nobody may reuse it. That is rarely what authors intend and it quietly blocks exactly the reuse you wanted.

Add a permissive licence file (MIT and BSD are the common choices for research code) unless your institution requires otherwise. It is one file and it is the difference between code others can build on and code they can only look at. The Open Source Initiative lists the standard options if you want to compare.

Getting it cited

Code citation works, and most people never set it up.

Add a `CITATION.cff` file to your repository — a small structured file saying how you want the software cited, with authors, title, version and DOI. GitHub reads it and shows a "Cite this repository" button. Then cite your own software in the paper's reference list, not only in the methods text, because reference lists are what indexing systems count.

Two further habits. Tag a release before submission and cite that specific version, since "the code" is not a stable object and a version is. And mention the DOI in the data availability or code availability statement rather than only in the methods, because that is where a reader looks for it.

This is not vanity. Research software gets used far more than it gets credited, and the credit gap is one reason good scientific software is hard to fund and hard to staff.

Two stories, same lesson

A reviewer I never met once sank a paper of ours, correctly. We had cited a GitHub link; by the time review came back the postdoc who wrote it had reorganised the repository and the paths in our methods no longer existed. The reviewer said, reasonably, that he could not evaluate what he could not run. The work was fine. The presentation of it was not, and we spent three weeks reconstructing and archiving what should have taken an afternoon at submission.

The counter-case was a postdoc in our group who got into the habit of tagging a release and depositing it the day she submitted anything. The first time, it felt like bureaucracy. Two years later a group in another country built on her method, cited the software DOI as well as the paper, and emailed to ask her to collaborate. None of that happens if the code is a link to a moving target.

The checklist, before you submit

  1. Clean checkout into an empty folder, follow your own README, confirm it runs.

  2. Confirm the outputs match the numbers in the manuscript.

  3. Add a licence and a `CITATION.cff`.

  4. Tag a release and let Zenodo mint the DOI.

  5. Cite the DOI in the reference list and name it in the code availability statement.

Step one catches more problems than the rest combined, because almost nobody tries to run their own code the way a stranger would. Hard-coded absolute paths are the usual casualty.

Reporting standards are slowly catching up with this — several checklists at the EQUATOR Network now ask about code availability, and the general case for it is set out in the FAIR principles, which apply to software as well as data. There is also a growing literature on how often shared code actually reproduces published results, and the answer is sobering enough to be worth reading (reproducibility of shared research code).

Keeping the deposit DOI with the manuscript and its sources is what makes this painless at submission instead of archaeological. That is what a project workspace is for, and if you want to see what others in your field deposit, look at how comparable papers handled it before you choose a repository.

Related reading

More on study types and reporting:

How to Share Code With Your Paper (and Get It Cited)