Skip to content

File Locking

Refringe edited this page Oct 24, 2026 · 8 revisions

File Locking

Anchor LFS implements the Git LFS File Locking API, allowing teams to coordinate concurrent edits on binary files that cannot be merged (e.g., images, 3D models, game assets).

How It Works

File locking lets a user declare exclusive edit access to a file. Other users can see the lock and avoid making conflicting changes. Locks are advisory. They don't prevent Git operations, but Git LFS clients warn when pushing changes to locked files owned by someone else.

Using File Locks

Lock a File

git lfs lock assets/model.bin

List Locks

git lfs locks

Unlock a File

# Unlock your own lock
git lfs unlock assets/model.bin

# Force unlock someone else's lock (needs maintain or admin on GitHub)
git lfs unlock --force assets/model.bin

Check Lock Status Before Pushing

git lfs locks --verify

This shows locks separated into "ours" (your locks) and "theirs" (other users' locks), helping you identify potential conflicts before pushing.

Lock Storage

Locks are stored as JSON files on the local filesystem, regardless of the configured storage backend:

<data_directory>/locks/<endpoint>/locks.json

Each endpoint has its own lock file. Its locks are also kept in memory, indexed by path, ID and creation time, so listing and verifying locks take about the same time however many there are; the index is reloaded when the file's identity, modification time or size changes. Creating or releasing a lock takes an advisory lock on locks.json.lock in the same directory and re-reads locks.json, so processes sharing a data_directory do not overwrite each other's changes. Each change rewrites the whole file, so with tens of thousands of locks creating or releasing one takes tens of milliseconds. Run one Anchor LFS instance per data_directory; see Storage Backends.

Lock Record Fields

Each lock record contains:

Field Description
id Unique identifier (UUID format)
path Relative file path within the repository
locked_at ISO 8601 timestamp of when the lock was created
owner.name Username of the lock owner

Lock Ownership

Lock ownership is determined by the authenticated user:

  • GitHub authentication: The lock owner is the GitHub username associated with the Personal Access Token
  • No authentication: The lock owner is the Basic Auth username if provided, or "anonymous" if no credentials are sent. Git LFS sends none unless lfs.<url>.access is basic (see Endpoints Without Authentication), so by default every lock is owned by anonymous and any client can release it, with or without --force. Any client can also send any username, so locks on a none endpoint are advisory only.

Only the lock owner can unlock a file. With the force flag, a user with the maintain or admin permission on the GitHub repository can also release someone else's lock (see Permissions). On a none endpoint, anyone can.

Pagination

Lock list and verify responses support cursor-based pagination:

  • Default limit: 100 locks per response
  • Maximum limit: 1000 locks per response
  • The response includes a next_cursor field. Pass this value as the cursor query parameter in the next request to fetch the next page.
  • An empty next_cursor means there are no more results.
  • The cursor marks a position in the list (locks are ordered by creation time, then ID), so releasing a lock between pages does not repeat or skip any of the others. Treat it as opaque; a cursor the server did not issue is rejected with 422.

Path Validation

Git LFS sends each lock path relative to the repository root, with / between directories. The server answers 422 to a lock request whose path breaks these rules:

  • Must be a relative path in valid UTF-8, with / between directories
  • Rejects empty, . and .. elements, so a leading or trailing /, //, ./ and traversal are all refused
  • Rejects null bytes
  • Allows backslashes, colons and Windows reserved names such as CON, which Git allows in file names on Linux and macOS

The rules are the same whichever operating system the server runs on.

Next Steps

Clone this wiki locally

⌂ 换网址