Locking Binary Files
Two programmers who edit the same C# file can merge their changes. Two artists who edit the same .psd, .blend, Unreal .uasset or .umap cannot: one of them will lose a day's work, because there's no way to merge two versions of a binary file. File locking prevents the conflict instead of resolving it: before editing, you take a lock; everyone else sees the file as locked (and read-only) until you push and release it.
Which files need locks
| Lock | Don't lock |
|---|---|
Image sources (.psd, .kra, .aseprite) |
code |
3D sources (.blend, .ma, .max) |
text-serialized scenes and prefabs that merge well (Unity YAML with Smart Merge, Godot .tscn/.tres) |
Unreal assets (.uasset, .umap) — always binary |
config files |
| Unity scenes, prefabs and assets that are binary or that your team can't merge reliably | exported, generated files (.fbx from a script, atlases): regenerate instead of locking |
| audio sessions and video project files |
Git LFS locking
Git LFS adds a lock API on the server (GitHub, GitLab and other LFS servers support it; check your host). Mark lockable types in .gitattributes:
*.psd filter=lfs diff=lfs merge=lfs -text lockable
*.blend filter=lfs diff=lfs merge=lfs -text lockable
*.uasset filter=lfs diff=lfs merge=lfs -text lockable
*.umap filter=lfs diff=lfs merge=lfs -text lockableWith lockable set, the LFS client checks those files out read-only, so an artist who forgets to lock notices when they try to save. A day of work then looks like this (sample session; needs the git-lfs client and a server):
$ git lfs lock Art/Hero/hero.blend
Locked Art/Hero/hero.blend
$ git lfs locks
Art/Hero/hero.blend ada ID:4211
Art/UI/hud.psd grace ID:4207
# ... edit, save, commit ...
$ git push
$ git lfs unlock Art/Hero/hero.blend
Unlocked Art/Hero/hero.blendUseful details:
git pushrefuses to push changes to files someone else has locked (with lock verification on, the default when the server supports locking; seelfs.<url>.locksverify).git lfs locks --verifylists locks as "ours" or "theirs" from your point of view.git lfs unlock --force <path>(or--id) breaks somebody else's lock, if the server lets you. Use it when a colleague went on holiday holding the lock, and tell them.- Locks are not tied to branches: a lock on
main'shero.blendalso blocks the same path on other branches. Teams that branch heavily need a policy for that. git config lfs.setlockablereadonly falseturns off the read-only behaviour if a tool can't cope with it (not recommended).
Engines know about locks
Editors integrate checkout and locking so artists don't use the command line:
- Unreal Engine's source control integration supports Perforce, Subversion and Git (including LFS locking via the Git plugin). With it enabled, the editor offers Check Out when you modify an asset, and shows who holds a lock. See Unreal version control.
- Unity integrates with Unity Version Control and Perforce (Project Settings → Version Control), with checkout and locking in the editor; Git LFS locking is used through external tools or plugins.
- Desktop Git clients such as GitHub Desktop, Fork and GitKraken show and manage LFS locks to varying degrees.
A runnable model of a lock server
The rules are simple enough to model completely, and modelling them makes the edge cases obvious:
class LockServer:
def __init__(self, lockable_ext):
self.lockable_ext = lockable_ext
self.locks = {} # path -> owner
def lock(self, user, path):
holder = self.locks.get(path)
if holder and holder != user:
return f"FAIL {user}: {path} is locked by {holder}"
self.locks[path] = user
return f"ok {user} locked {path}"
def unlock(self, user, path, force=False):
holder = self.locks.get(path)
if holder is None:
return f"ok {path} was not locked"
if holder != user and not force:
return f"FAIL {user}: {path} is locked by {holder} (use --force)"
del self.locks[path]
return f"ok {user} unlocked {path}" + (f" (lock of {holder} broken)" if holder != user else "")
def push(self, user, changed):
for path in changed:
needs_lock = path.endswith(self.lockable_ext)
holder = self.locks.get(path)
if holder and holder != user:
return f"FAIL {user} push: {path} is locked by {holder}"
if needs_lock and holder is None:
return f"WARN {user} push: {path} is lockable but was not locked first"
return f"ok {user} pushed {', '.join(changed)}"
server = LockServer((".blend", ".psd", ".umap"))
print(server.lock("ada", "Art/hero.blend"))
print(server.lock("grace", "Art/hero.blend"))
print(server.push("grace", ["Art/hero.blend"]))
print(server.push("ada", ["Art/hero.blend", "src/Player.cs"]))
print(server.push("grace", ["Maps/Level1.umap"]))
print(server.unlock("grace", "Art/hero.blend"))
print(server.unlock("grace", "Art/hero.blend", force=True))ok ada locked Art/hero.blend
FAIL grace: Art/hero.blend is locked by ada
FAIL grace push: Art/hero.blend is locked by ada
ok ada pushed Art/hero.blend, src/Player.cs
WARN grace push: Maps/Level1.umap is lockable but was not locked first
FAIL grace: Art/hero.blend is locked by ada (use --force)
ok grace unlocked Art/hero.blend (lock of ada broken)
The WARN line is a policy choice: Git LFS itself doesn't require a lock before you push a lockable file, it only prevents pushes over someone else's lock. Teams that want "lock first, always" enforce it with a server-side check or with the read-only checkout habit.
Habits that make locking work
- Lock just before editing, unlock right after pushing. A lock held overnight blocks someone else's morning.
- Pull before you lock. Locking an old version and then editing it still loses work: the lock doesn't update your copy.
- Split big binary files. One
.umapfor a whole level means one person at a time can work on that level. Unreal's World Partition with One File Per Actor stores each actor in its own file, so many people can edit the same map; in Unity, split a scene into additive scenes or prefabs. - Make lock status visible: a bot that posts long-held locks, or a dashboard.
Test yourself
Why can't two artists simply merge their changes to the same .psd file?
- Git forbids it
- Binary files have no meaningful line-based merge; one version wins and the other's work is lost
- PSD files are too large
- LFS doesn't store PSDs
What does the lockable attribute make the Git LFS client do?
- Encrypt the file
- Check the file out read-only until you take a lock
- Store it outside LFS
- Push it automatically
A lock on Maps/Level1.umap is held on the main branch. Is the same path locked on a feature branch?
- No, locks are per branch
- Yes, Git LFS locks are per path, not per branch
- Only if the branch is pushed
- Only for .umap files