Occlude
Book a call

Can Git restrict read access to a folder?

No. GitHub, GitLab and Bitbucket grant read access per repository, and every finer rule controls writing. What each offers, and which systems restrict reads.

No. Git has no way to let someone read one folder of a repository and not another, and GitHub, GitLab and Bitbucket do not add one. On all three, read access is granted per repository. Every finer rule they offer controls who may write, not who may read.

Two panels. On GitHub, GitLab and Bitbucket one grant covers the whole repository, so the contractor's clone has every folder. On Perforce and Subversion the billing folder is denied, it never reaches the contractor's disk, and their build fails on billingTwo panels. On GitHub, GitLab and Bitbucket one grant covers the whole repository, so the contractor's clone has every folder. On Perforce and Subversion the billing folder is denied, it never reaches the contractor's disk, and their build fails on billing
Git hosts grant a whole repository or none of it. Perforce and Subversion can deny a path, and the build that needs it breaks.

This page shows what each host documents, which version control systems do restrict reads by path, and what that costs.

Why Git works this way

A Git clone is a full copy of the repository and its history. The server's only decision is whether to hand that copy over. Once it has, there is no server left between the person and the files.

One of the most active answerers of Git questions on Stack Overflow put it in a sentence, replying to someone who wanted a contractor to see part of a monorepo:

"Git itself has no authorization (or authentication for that matter)."

Hosts add accounts and roles on top, and they add them at the level Git gives them: the repository.

What each host offers

HostSmallest unit for read accessFiner rules it does offerWhat those rules control
GitHubThe repositoryBranch protection, rulesets, code ownersWho may push, merge or must review
GitLabThe projectProtected branches, push rules, code ownersWho may push, merge or must review
Bitbucket CloudThe repositoryBranch permissionsWho may write or merge to a branch

GitHub. Access is a role on a repository. The lowest role, Read, is described as "Recommended for non-code contributors who want to view or discuss your project", and the same table shows every role, Read included, able to pull the repository. Nothing in the role table is scoped to a path.

GitLab. Roles are held on a project or a group. The permissions table lists "Pull project code" as a project permission, and protected branches are described in terms of who can push and who can merge.

Bitbucket Cloud. The documentation defines the Read level in one line:

"Allows users to view, clone, and fork the repository code but not push changes."

Its branch permissions let an admin "Closely control which users or groups can write or merge to any branch." Again, writing.

So on all three, the answer to "can this person read billing/" is the same as the answer to "can this person clone the repository".

What about sparse checkout and partial clone?

They are for speed, not secrecy. Git's manual describes sparse checkout as a way to "Reduce your working tree to a subset of tracked files". It changes which files appear in your folder. It does not change which files you are allowed to fetch, and the person can widen it whenever they like.

Partial clone is the same kind of tool. Git's documentation calls it "a performance optimization": some files are not downloaded until they are needed, and anyone with read access can fetch them when they are.

Systems that do restrict reads by path

Two long-established systems can deny one user the right to read one path.

SystemRead control by pathWhat the user getsWhat happens to their build
PerforceYes, in the protections tableDenied files never syncFails where their code depends on a denied file
SubversionYes, path-based authorizationUnreadable directories are left out of the checkoutFails the same way

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", and the same chapter carries a section titled "Do You Really Need Path-Based Access Control?"

Both do what they say. The file is not on the person's machine. Neither offers anything for the compiler on that machine, which now cannot find a file the code imports.

What people do instead

If you are on Git and need someone to see only part of your code, the realistic choices are these.

  • Split the repository so that the boundary you need is a repository boundary. This is the standard answer and, where the code divides cleanly, the right one.
  • Move the work to a cloud workspace so that no copy reaches the person's laptop. They can still read every file while they work.
  • Move to Perforce, if broken contractor builds are acceptable.
  • Use code masking, where the person works in a workspace that shows them part of the repository while the build uses all of it.

How to give a contractor access to part of a repository compares these side by side.

Where Occlude fits

Occlude gives contractors and AI agents partial repository access, which we call code masking. Your repository stays on the host you already use. Occlude runs in your cloud, holds the clone there, and decides what each person can see, while the compiler, the tests and the dev server see every file. Occlude is new. How a build runs shows a contractor building code they cannot read.

If your repositories already divide along the line you need, you do not need it. Repository permissions do that job for free.

Sources

Each quotation was read on its source page on 28 November 2026. The Stack Overflow quotation is its author's view.

Want to go through this for your codebase?

All posts