Git, Git LFS & .gitignore
Game projects break the assumptions plain Git was designed for. A web app is mostly small text files; a game is gigabytes of textures, models and audio, plus caches the engine can regenerate at any time. Set up three files on day one (.gitignore, .gitattributes and Git LFS) and the repository stays small, fast and recoverable.
If Git itself is new, start with the Git course; this lesson covers what is specific to games.
The three kinds of files
| Kind | Examples | What to do |
|---|---|---|
| Generated | Unity Library/, Unreal Intermediate/ and DerivedDataCache/, Godot .godot/, builds |
ignore: the engine rebuilds them, and they are huge and machine-specific |
| Text | scripts, Unity scenes and prefabs saved as YAML, Godot .tscn/.tres, config |
normal Git: diffs and merges work |
| Large binary | .png, .psd, .fbx, .wav, .blend, Unreal .uasset/.umap |
Git LFS: the repository stores a small pointer, the content lives in LFS storage |
Git keeps every version of every file forever. Commit a 200 MB texture ten times and every clone downloads 2 GB, even after you delete it. LFS downloads only the versions a checkout needs.
.gitignore per engine
Unity:
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/
/[Mm]emoryCaptures/
.vs/
.idea/
*.csproj
*.sln
*.userKeep Assets/, Packages/ and ProjectSettings/, including every .meta file. A .meta file holds the asset's GUID; lose it and every reference to that asset breaks.
Unreal Engine:
Binaries/
DerivedDataCache/
Intermediate/
Saved/
.vs/
*.sln
Plugins/*/Binaries/
Plugins/*/Intermediate/Godot 4 creates a suitable .gitignore for new projects. The essential line is .godot/, the import cache.
Git LFS and a .gitattributes for Unity
Install the LFS extension once per machine, then track binary types per repository:
git lfs install # once per machine: adds the LFS hooks
git lfs track "*.psd" # appends a rule to .gitattributes
git add .gitattributes
git lfs ls-files # files currently stored in LFS
git lfs lock Assets/Art/hero.psd # optional: lock a file before editing itMost teams write .gitattributes by hand instead. A sample for a Unity project:
# Default: normalize line endings of text files
* text=auto
# Unity YAML assets: text, LF line endings (set Asset Serialization to Force Text)
*.cs text diff=csharp
*.unity text eol=lf
*.prefab text eol=lf
*.mat text eol=lf
*.anim text eol=lf
*.controller text eol=lf
*.meta text eol=lf
*.asset text eol=lf
# Images
*.png filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
*.tga filter=lfs diff=lfs merge=lfs -text
*.psd filter=lfs diff=lfs merge=lfs -text lockable
# 3D models and source files
*.fbx filter=lfs diff=lfs merge=lfs -text
*.blend filter=lfs diff=lfs merge=lfs -text lockable
# Audio and video
*.wav filter=lfs diff=lfs merge=lfs -text
*.ogg filter=lfs diff=lfs merge=lfs -text
*.mp4 filter=lfs diff=lfs merge=lfs -text
# Fonts and native libraries
*.ttf filter=lfs diff=lfs merge=lfs -text
*.dll filter=lfs diff=lfs merge=lfs -textNotes on this file:
- In Unity, set Project Settings → Editor → Asset Serialization Mode to Force Text (the default in new projects) so scenes and prefabs are YAML and can be diffed. A few assets, such as baked lighting data, stay binary even then; if your project has many, move those patterns to LFS.
- Unity ships a YAML merge tool (UnityYAMLMerge, "Smart Merge"). You can register it as a Git merge driver for
.unityand.prefabfiles; see Unity's docs on Smart Merge. lockablemakes Git LFS mark the file read-only until yougit lfs lockit, which prevents two artists from editing the same.psdand producing a conflict nobody can merge.
More on the mechanics: Git LFS, .gitignore, .gitattributes.
A model of the rules
This snippet sorts a few project paths the way the files above do: ignored, stored in LFS, or committed as text. Real Git uses full glob matching; this model only checks folder prefixes and extensions, but it is a handy way to reason about a new file type.
const ignoredFolders = ["Library/", "Temp/", "Logs/", "Builds/", "UserSettings/"];
const lfsExtensions = [".png", ".psd", ".fbx", ".blend", ".wav", ".ogg"];
function classify(path) {
if (ignoredFolders.some((dir) => path.startsWith(dir))) return "ignored";
const ext = path.slice(path.lastIndexOf(".")).toLowerCase();
return lfsExtensions.includes(ext) ? "LFS" : "text";
}
const paths = [
"Assets/Scripts/Player.cs",
"Assets/Scripts/Player.cs.meta",
"Assets/Art/Hero.PSD",
"Assets/Scenes/Level1.unity",
"Library/ArtifactDB",
"Assets/Audio/jump.wav",
"Builds/Game.exe",
];
for (const p of paths) console.log(`${classify(p).padEnd(7)} ${p}`);text Assets/Scripts/Player.cs
text Assets/Scripts/Player.cs.meta
LFS Assets/Art/Hero.PSD
text Assets/Scenes/Level1.unity
ignored Library/ArtifactDB
LFS Assets/Audio/jump.wav
ignored Builds/Game.exe
Note:
Hero.PSDlands in LFS here because the model lowercases the extension. Git's pattern matching is case-sensitive on a case-sensitive file system such as Linux, so*.psdmay not matchHero.PSDon every teammate's machine (or your CI server). Agree on lowercase extensions, or add both patterns.
Habits that save projects
- Set up LFS before the first binary commit. Moving existing history into LFS (
git lfs migrate) rewrites every commit hash, which is painful once others have cloned. - Commit small and often, with messages that say what changed in the game: "Enemy patrol waits 1 s at each point", not "fixes".
- Never commit secrets: signing keystores, store API keys, server passwords. Keep them outside the repository and out of builds.
- Tag releases (
v0.3-jam-build) so you can rebuild exactly what players got. - Alternatives exist. Many larger studios use Perforce (Helix Core), especially with Unreal; Unity also offers Unity Version Control (formerly Plastic SCM). Git + LFS is the common choice for solo developers and small teams.
Test yourself
What should happen to Unity's Library/ folder?
- Commit it so builds are faster
- Store it in Git LFS
- Ignore it; Unity regenerates it
- Delete it after every session
Why must Unity .meta files be committed?
- They contain the build settings
- They hold each asset's GUID, which references depend on
- They are needed by Git LFS
- They don't need to be
What does lockable in .gitattributes do with Git LFS?
- Encrypts the file
- Makes the file read-only until you lock it, preventing unmergeable parallel edits
- Stops the file from being pushed
- Compresses the file