With Git LFS file locking, how do you stop two artists overwriting each other's work on the same binary scene file?
answer
- binaries have no three-way merge
- a record on the server
- read-only until you hold it
- the pre-push hook checks theirs
basics
~20 sMark the file type lockable and have artists run git lfs lock before editing. The LFS server records one owner, other clones keep the file read-only, and with lock verification on, a push changing someone else's locked file is refused.
solid answer
~50 sGit cannot merge two edits to a binary scene file, so the second push either loses work or overwrites someone's. Git LFS locking serialises editing instead. Paths marked lockable are checked out read-only by the LFS hooks unless you hold the lock. `git lfs lock scenes/harbor.scene` asks the LFS server's locking API to record you as the owner, and the server refuses a second lock on the same path; `git lfs locks` shows who holds what, and `git lfs unlock` releases it after you push. On push, the pre-push hook asks the server for locks; with `lfs.<url>.locksverify` set to `true` it halts if you change a file someone else has locked, and on lock-server errors too. `git lfs unlock --force` breaks a stale lock. The check runs in client hooks, so it only binds clones that have them unless the server also enforces locks.
code
bash · 6 linesgit lfs locks # who holds what
git lfs lock scenes/harbor.scene # take the lock before editing
# ... edit, then commit and push ...
git push origin main
git lfs unlock scenes/harbor.scene # release it for the next artist
git config lfs.https://git.example.com/.locksverify truego deeper
Remember why binaries need locks at all: Git cannot merge them. Know the three commands: git lfs lock, git lfs locks and git lfs unlock.
Explain where the lock lives (the LFS server), how lockable files become read-only through the hooks, and how the pre-push hook checks for other users' locks.
Show you know the gaps: locksverify states, clones without hooks, stale locks and --force, and when a team needs server-side enforcement rather than trust in clients.
Weigh locking's coordination cost against the work lost to unmergeable conflicts, and decide which file types justify a lock-first workflow for the whole team.
## Why binaries need locks Git's normal workflow assumes that two people can edit the same file and a **three-way merge** reconciles their changes. That works for text. It does not work for a binary scene file, a layered image or an audio project: Git has no way to combine two edited versions, so whoever pushes second either throws away their own work or overwrites the first person's. Teams adopt Git LFS for exactly these files, and **file locking** is the LFS answer to the merge problem: instead of merging, it makes editing **one person at a time**. ## The pieces | Piece | What it does | |---|---| | lockable paths | marked when tracking is set up; the files are expected to be locked before editing | | read-only checkout | LFS hooks make lockable files read-only in the working copy unless you hold the lock | | `git lfs lock <path>` | asks the LFS server to record you as the lock owner; the file must exist locally | | `git lfs locks` | lists current locks from the server (`--local` shows only your cached locks, `--verify` marks the ones you really own) | | `git lfs unlock <path>` | releases your lock; the file must exist and have a clean status unless you add `--force` | | `git lfs unlock --force` | tells the server to remove a lock even if another user owns it | The lock lives on the **LFS server**, behind its **File Locking API** (create, list, verify, delete under the server's `/locks` URLs). It is not stored in a commit, a pointer file or `.gitattributes`. The server should require push access to lock, and it refuses a second lock on the same path with a conflict. ## The workflow 1. Alice runs `git lfs lock scenes/harbor.scene`; the server records her as owner and her copy becomes writable. 2. Bob's clone keeps the file read-only, and `git lfs locks` shows that Alice holds it. 3. Alice edits, commits and pushes, then runs `git lfs unlock scenes/harbor.scene`. 4. Bob pulls Alice's version, locks the file himself and starts from her work. ## How the push check works The client-side guard is the **pre-push hook**. Before uploading, it asks the server which locks are "ours" and which are "theirs" and, when verification is enabled, halts the push if it changes a file in someone else's lock. Its strictness is controlled by `lfs.<url>.locksverify`: | Value | Behaviour | |---|---| | `true` | verify locks; halt on files locked by others and on lock-server errors | | `false` | skip the lock check entirely | | unset | attempt the check and only warn on errors; whether a foreign lock halts the push depends on what the client has detected about the server | Setting the key to `true` explicitly for the host (it supports Git's per-URL matching) is the reliable choice for a team that depends on locks. Setting it to `false` is right when you do not use locking, or when your server verifies locked files on push itself. ## Reading lock state `git lfs locks` has several views, and choosing the right one avoids confusion: - plain `git lfs locks` asks the server for current locks; `--path` or `--id` return a single lock, and `--limit` caps the list; - `--local` lists only your own locks cached locally, without a server call; - `--cached` shows the last list fetched from the server, including other users' locks, for when you are offline, with no guarantee it is still current; - `--verify` asks the server who owns each lock and marks yours, which also reveals a lock taken from another clone of yours or one someone has broken; - `--json` on lock, unlock and locks prints machine-readable output for tooling such as editor plugins. Two preconditions trip people up: `git lfs lock` needs the file to exist in the working copy, and `git lfs unlock` needs the file to exist with a clean status unless you pass `--force`. ## The limits of locking - **The hook is client-side.** A clone without the LFS hooks, or a push that skips them, is not stopped by the client check; only a server that enforces locks on push stops it. - **Read-only is local.** It is a file permission the hooks set, which an editor or a user can override. - **Locks are coarse.** The locking API describes itself as supporting the simplest case, single-branch locking: plan on one lock per path for the team, not per branch. - **Stale locks happen.** A lock owner on holiday blocks everyone; `git lfs unlock --force` (or `--id` with a lock ID) breaks it, and the owner's `git lfs locks --verify` will then show the lock as broken. - **Locks do not merge anything.** They prevent the conflict; they do not resolve one that already happened.
- An artist went on holiday holding the lock on a file the team needs. What do you do?Run `git lfs unlock --force scenes/harbor.scene` (or `--id` with the lock's ID from `git lfs locks`). It tells the server to remove a lock owned by another user; the server decides whether you may. Tell the owner: if they kept editing, their `git lfs locks --verify` shows the lock as broken, and their changes now need reconciling by hand.
- Why might a teammate's push still change a file you have locked?The check runs in the client's pre-push hook. If their `lfs.<url>.locksverify` is `false` the check is skipped; if it is unset and the lock call errors, they only get a warning; and a clone without the LFS hooks never runs it. Only a server that enforces locks on push closes that gap.
File locking is like the sign-out sheet for a shared workshop key: the sheet at the front desk (the LFS server) says who has the key, and other doors stay shut (read-only) until it comes back. Someone climbing in through a window (a push without the LFS hooks) is not stopped by the sheet itself.
- Git LFS locks are stored in the repository and travel with each commit.
- Marking a file lockable lets Git LFS merge two artists' edits automatically.
- Once a file is locked, nobody can possibly push a change to it.
- The read-only bit on lockable files is enforced by the LFS server.
- Only the lock owner can ever remove a Git LFS lock.