TExcelTAD
Home › Assets, Tools & Shipping › Locking Binary Files

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:

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 lockable

With 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):

bash
$ 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.blend

Useful details:

  • git push refuses to push changes to files someone else has locked (with lock verification on, the default when the server supports locking; see lfs.<url>.locksverify).
  • git lfs locks --verify lists 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's hero.blend also blocks the same path on other branches. Teams that branch heavily need a policy for that.
  • git config lfs.setlockablereadonly false turns 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:

python · try it yourself
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

  1. Lock just before editing, unlock right after pushing. A lock held overnight blocks someone else's morning.
  2. Pull before you lock. Locking an old version and then editing it still loses work: the lock doesn't update your copy.
  3. Split big binary files. One .umap for 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.
  4. 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?

  1. Git forbids it
  2. Binary files have no meaningful line-based merge; one version wins and the other's work is lost
  3. PSD files are too large
  4. LFS doesn't store PSDs

What does the lockable attribute make the Git LFS client do?

  1. Encrypt the file
  2. Check the file out read-only until you take a lock
  3. Store it outside LFS
  4. Push it automatically

A lock on Maps/Level1.umap is held on the main branch. Is the same path locked on a feature branch?

  1. No, locks are per branch
  2. Yes, Git LFS locks are per path, not per branch
  3. Only if the branch is pushed
  4. Only for .umap files