File locking
- Tier: Free, Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
File locking prevents multiple people from editing the same file simultaneously, which helps avoid merge conflicts. File locking is especially valuable for binary files that cannot be merged like design files, videos, and other non-text content.
GitLab supports two different types of file locking:
- Exclusive file locks: Applied through the
command line with Git LFS and
.gitattributes
. These locks prevent modifications to locked files on any branch. - Default branch file and directory locks: Applied through the GitLab UI. These locks prevent modifications to files and directories on the default branch only.
Permissions
You must have at least the Developer role for the project to create, view, or manage file locks. For more information, see Roles and permissions.
Default branch file and directory locks
- Tier: Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
Default branch locks apply only to the default branch set in your project’s settings. These locks help maintain stability in your default branch without blocking collaborator workflows in other branches.
When a file or directory is locked by a user:
- Only the user who created the lock can modify the file or directory on the default branch.
- For other users, the locked file or directory is read-only on the default branch.
- Direct changes to locked files or directories on the default branch are blocked.
- Merge requests that modify locked files or directories cannot be merged to the default branch.
On non-default branches, all users can still modify locked files and directories. A Lock status is visible on these files and directories. This helps team members to be aware of in-flight work without restricting their workflow on other branches.
Lock a file or directory
Prerequisites:
- You must have at least the Developer role for the project.
To lock a file or directory:
- On the left sidebar, select Search or go to and find your project.
- Go to the file or directory you want to lock.
- In the upper-right corner, select Lock.
- On the confirmation dialog, select OK.
If Lock is not enabled, you don’t have the required permissions to lock the file.
To see who locked a directory, if it wasn’t you, hover over the Lock. For a similar function for locked files, see issue 4623.
View and remove locks
To view locked files:
- On the left sidebar, select Search or go to and find your project.
- Select Code > Locked files.
The Locked files page displays all files locked with either Git LFS exclusive locks or the GitLab UI.
Prerequisites:
- You must be the user who created the lock.
- You must have at least the Maintainer role for the project.
To remove a lock:
- On the left sidebar, select Search or go to and find your project.
- Go to the file you want to unlock.
- Select Unlock.
- On the confirmation dialog, select Unlock.
Related topics
Docs
Edit this page to fix an error or add an improvement in a merge request.
Create an issue to suggest an improvement to this page.
Product
Create an issue if there's something you don't like about this feature.
Propose functionality by submitting a feature request.
Feature availability and product trials
View pricing to see all GitLab tiers and features, or to upgrade.
Try GitLab for free with access to all features for 30 days.
Get help
If you didn't find what you were looking for, search the docs.
If you want help with something specific and could use community support, post on the GitLab forum.
For problems setting up or using this feature (depending on your GitLab subscription).
Request support