# How to give a contractor access to part of a repository

> Git grants read access to a whole repository or none of it. Seven ways teams work around that for contractors, what each costs, and when each is right.

Source: https://occlude.dev/blog/contractor-access-to-part-of-a-repository/ · 6 November 2026, updated 28 November 2026 · By Aman Sharma


Git cannot give someone read access to part of a repository. Access is to the whole repository or to none of it, so every way of showing a contractor only some of your code is a workaround, and each one trades away either the secrecy or the working build.

![A table of the seven options. NDA, sparse checkout and a cloud workspace let the contractor read everything and the build works. Splitting builds against mocks, path permissions break the build, binaries work until the code changes, and code masking shows the task's files with a working build](https://occlude.dev/figures/seven-options.webp)

*The seven options, by how much of the repository the contractor can read and whether their build still works.*

This page goes through the seven options teams actually use, including the cases where the cheap one is the right one.

## Why Git cannot do it

The question is old. On GitLab's forum a project owner asked it this way:

> "Can I set things so e.g. the front end developers only have access to their front end code and not the back end server code etc that others are working on?"

The reply from another forum member is the answer most people still get:

> "The granularity of access is THE ENTIRE REPOSITORY."

GitHub, GitLab and Bitbucket can restrict who *writes* to a branch, and GitHub can also block pushes that change a given path. None of them restricts who *reads* a folder inside a repository the person can clone. A sparse checkout does not change this: it controls which files appear in the working folder, not which files the person is allowed to fetch.

On Stack Overflow, under the same question asked about a monorepo and a contractor, a long-standing Git expert left this comment:

> "This is a problem, and there are no good solutions."

## The seven options

| Option | What the contractor can read | Does their build work? | What it costs you |
|---|---|---|---|
| NDA and full access | Everything | Yes | Nothing up front. You rely on the contract |
| Split the repository | Only their repository | Only against mocks or published packages | A sync step on every change that crosses the line |
| Sparse checkout | Everything, if they ask for it | Yes | Nothing, and it protects nothing |
| Version control with path permissions | Only permitted paths | No, when their code depends on a denied path | A move to Perforce or Subversion, and broken builds |
| A cloud workspace or virtual desktop | Everything, inside the workspace | Yes | A per-seat fee. The code stays off their laptop |
| Ship binaries | Only the interface | Yes, until the protected code changes | A release process for the protected module |
| Code masking | Only the files their task needs | Yes | A product running in your cloud |

## NDA and full access

What almost everyone does. It is free and immediate, and for a small team with a contractor they know, it is often the right call.

Its limit is that it is a promise, not a control. A founder on Hacker News put the discomfort plainly: "if you want to hire outside help, you have to share everything." If an auditor asks who could read the payment code, the answer is everyone you ever gave access to.

## Split the repository

The standard advice, and free. Move the sensitive code to its own repository, or carve the contractor's part out with a subtree or a submodule, and give them only that.

It works well when there is a clean line: a mobile app that talks to a backend over a documented interface, for example. It works badly in a monorepo where the two sides share types and change together. Then the contractor builds against a stand-in, the stand-in drifts from the real code, and someone on your team spends part of every week carrying changes across.

## Sparse checkout

Worth naming because it is often suggested. A sparse checkout makes a large repository lighter to work in by leaving most files out of the working folder. It is a convenience. The person still has read access to the whole repository and can fetch the rest with one command.

It also shows the build problem in miniature. An open issue on Bazel, the build tool, describes what happens when files are left out: a user "has to maintain two independent sources of truth for which files are needed in a build."

## Version control with path permissions

Perforce and Subversion can deny one user the right to read one path. This is real access control, and if you already run Perforce it may be all you need.

The cost is the build. Perforce's command reference says of the read right: "If this right is denied, users cannot use p4 print, p4 diff, or p4 sync on files." Subversion's manual says an unreadable subdirectory is "skipped altogether" on checkout. Either way the file is not on the contractor's machine, so anything of theirs that imports it does not compile. [The longer version is here](https://occlude.dev/blog/perforce-controls-what-syncs/).

## A cloud workspace or virtual desktop

Codespaces, Coder, Citrix, Amazon WorkSpaces. The contractor works on a machine you own, and the code never reaches their laptop. If your worry is a copy walking out of the door, this answers it, and it is the option with an established budget line.

It does not narrow what they can read. Inside the workspace, access is the repository. GitHub's documentation for Codespaces says of the access token: "The token will be scoped for read/write access to the repository."

## Ship binaries

Compile the protected module and hand over the compiled form with its interface. The contractor's build links against it and never sees the source. This is common where suppliers exchange components, and it is a good fit for a library that changes a few times a year.

It fits badly when the contractor works next to the protected code every day, because the binary is out of date as soon as that code changes.

## Code masking

The newest option, and the one we build. The contractor works in a workspace in your cloud. They see the files their task needs. The compiler, the tests and the dev server see every file, so the build passes without mocks. Nothing is copied to their laptop, and every file they open is on a record you keep. [What is code masking?](https://occlude.dev/blog/what-is-code-masking/) has the definition.

The costs are honest ones: it is a product to run, and Occlude is new. Getting started is a call with us, not a download.

## Which one to pick

- **Your sensitive code already sits behind a clean interface.** Split the repository. Nothing else is worth the money.
- **Your only worry is copies leaving.** A cloud workspace does that today.
- **You run Perforce and can live with contractors who cannot build everything.** Use its protections.
- **The protected module rarely changes.** Ship it as a binary.
- **It is a monorepo, the two sides change together, and some of it must not be read.** This is the case the first five options do not cover, and the one code masking is for.
- **None of this is worth the trouble for your team.** An NDA and full access is a legitimate answer. Most companies choose it.

## Sources

Each quotation was read on its source page on 28 November 2026. Forum and comment quotations are the views of the people who wrote them, not official positions of GitLab, Stack Overflow or GitHub.

- [GitLab forum: Only allow specific developers access to certain files?](https://forum.gitlab.com/t/only-allow-specific-developers-access-to-certain-files/3105)
- [Stack Overflow: Granular access to directories within monorepo](https://stackoverflow.com/questions/54408829/granular-access-to-directories-within-monorepo)
- [Hacker News, comment on "Monorepo – Our Experience"](https://news.ycombinator.com/item?id=42074954)
- [Bazel issue on sparse checkouts](https://github.com/bazelbuild/bazel/issues/16380)
- [p4 protect, the Helix Core command reference](https://help.perforce.com/helix-core/server-apps/cmdref/current/Content/CmdRef/p4_protect.html)
- [Path-Based Authorization, Version Control with Subversion](https://svnbook.red-bean.com/en/1.7/svn.serverconfig.pathbasedauthz.html)
- [Security in GitHub Codespaces](https://docs.github.com/en/codespaces/reference/security-in-github-codespaces)
