如何让GitLab仓库可浏览但禁止匿名克隆?
How to Allow Public Web Browsing but Block Anonymous Cloning in GitLab
Absolutely, you can set up your GitLab repository to let anyone browse your code and commit history via the web interface, while preventing anonymous users from cloning or forking the repo. Here's how to do it step by step:
- Keep the repository public: First, ensure your repo is set to "Public" visibility (under Settings > General > Visibility, project features, permissions). This lets anyone view the code through GitLab's web UI.
- Block anonymous Git access:
- Navigate to your project's Settings > Repository.
- Scroll down to the Permissions section.
- Find the row labeled "Anonymous users" and set the Repository permission to No access. This blocks unauthenticated users from cloning via any protocol.
- For extra assurance, you can also disable the unauthenticated
git://protocol entirely: in the Git access protocols section, uncheck the box next to "Git" (leave HTTPS enabled, but since anonymous users have no access, they still can't clone over HTTPS).
With these settings in place:
- Anyone can view your HTML/CSS projects, commit history, and file structure through the GitLab web page.
- Anonymous users won't be able to clone, pull, or fork the repo directly. Forking requires being logged into GitLab and having explicit permission, which they won't have here.
- As you noted, people can still view page source or save individual files, but that's a far higher barrier than cloning the entire repo with its full history and structure.
If you ever need to let specific people clone the repo (like a potential employer you're in contact with), you can add them as a project member with Reporter access or higher—this will let them clone while keeping anonymous access blocked.
内容的提问来源于stack exchange,提问作者K4ll-of-D00ty
相关产品推荐
相关产品推荐

