Git Version Control for Game Devs: Complete Setup Guide

Git and Git LFS configured properly for a game project: ignore rules, large asset tracking, branching, GitHub pull requests, and the recovery commands that save a bad afternoon.

Git version control for game devs is not really about sharing code with other people. It is about being able to delete something enormous and get it back. A game project accumulates layers - a character with forty animations, a shader that took an afternoon to tune, an entire level that took a week - and at some point you will want to throw all of it away and try something else. Without a version control system, that decision is irreversible. With one, it is a branch you delete. The reason most developers abandon Git in the first month is not the command line; it is that a game project contains large binary files, and a naive Git setup turns a folder of artwork into a repository that takes minutes to clone and grows without limit. That problem has an exact solution - Git LFS, with a documented set of limits and quotas - and once it is configured, the rest of the workflow is ordinary Git with a slightly unusual set of file types. This guide is written for someone who has never used Git, or who has used it for code and is now looking at a Unity or Godot project full of .psd, .blend and .fbx files and wondering what the rules are. It works from the official Git, Git LFS and GitHub documentation rather than from folklore, because the folklore is where most of the wrong advice lives.

Why a game project needs version control

Game dev version control is not a special discipline. The commands are the same ones every software project uses, and the mental model is the same one. What is different about games is the shape of the assets. Code is text: it diffs cleanly, it merges reasonably, and a version of it is small. A three-hour sculpt in ZBrush, a layered Photoshop file, a Blender scene with a rigged character and a baked texture set, a Unity project with an imported asset cache - these are large, they are binary, and they do not diff at all. Two developers who both touched the same .blend cannot merge their changes, because there is no meaningful line-based merge for a binary blob.

This produces the specific failure mode that makes game projects hostile to naive setups. Every developer keeps a local copy of the large files. Every commit carries some of those bytes. The repository grows by the size of the asset every time it changes, because Git stores each version of a file as a separate object. Six months later the repository is several gigabytes, cloning it takes a coffee break, and nobody can remember why. The fix is not a better branching model. The fix is to keep the binary payloads out of Git's object database and let a dedicated service store them, which is exactly what Git LFS does.

The shape of the problem

Three file categories, three different rules

Source code and scene files are text and belong in Git, committed freely. Derived caches such as a Unity Library folder or a Godot .godot folder are regenerated by the engine and belong in neither Git nor LFS - they are ignored outright. Large authored binaries - .psd, .blend, .kra, .fbx, .wav - are irreplaceable and belong in Git LFS, because they must be versioned but must not bloat the repository. Nearly every confusing situation in Git LFS setup comes from putting a file in the wrong one of those three buckets.

The other reason to adopt this early is that the tooling ecosystem assumes it. Every engine tutorial about a shader bug, every forum thread about a broken scene file and every bug report worth reading starts with a repository, a commit hash and a reproduction branch. If you are not using Git, you cannot participate in that conversation, and if you are not using Git LFS, you cannot participate in it without checking out several gigabytes first. The game dev tools index has more on the wider tooling stack; the quick start guide is where most projects should begin before they reach version control.

Writing .gitignore rules for Unity and Godot

The ignore file decides what never enters the repository, and it must be written before the first commit rather than retrofitted after the fact. Retrofitting means rewriting history to purge the files you accidentally committed, and the migration tooling for that is not what you want to be learning on the same day you are setting up a project. Write the rules first, verify them with the check command, then commit.

# ---- Unity ----
[Ll]ibrary/
[Tt]emp/
[Oo]bj/
[Bb]uild/
[Bb]uilds/
[Ll]ogs/
[Uu]ser[Ss]ettings/
*.csproj
*.sln
*.user

# ---- Godot ----
.godot/
export/
*.translation

# ---- 系统与编辑器 ----
.DS_Store
Thumbs.db
*.tmp
*.swp
.idea/
.vscode/

# ---- 构建产物 ----
build/
dist/
*.apk
*.exe

The rules themselves follow a documented precedence, and understanding it removes almost all of the guesswork. From highest to lowest, the order is: the .gitignore file in the directory containing the path, then the per-repository exclude file at .git/info/exclude, then the file named by the core.excludesFile configuration variable, whose default is the user's global ignore file. Within one level of precedence, the last matching pattern decides the outcome, which is what makes the negation syntax work: a pattern prefixed with an exclamation mark re-includes a path that an earlier pattern excluded.

The one limitation that catches everybody: it is not possible to re-include a file if one of its parent directories is excluded, because Git does not descend into excluded directories at all. If you exclude Assets/ and then try to re-include Assets/Art/Hero.psd, the negation has no effect. You have to stop excluding the directory itself and exclude its contents instead.

The engine-specific part is easier. In Unity, the Library folder is an import cache whose entire contents can be regenerated by the editor from the source assets, so it is excluded, along with Temp, Logs, obj, Build, UserSettings and the generated solution and project files. In Godot, the .godot folder is the import cache and the export output folders are build artifacts. What must never be ignored is the authored content: scenes, scripts, shaders, animation data, the project settings file, the export presets and the source assets. The failure mode of getting this wrong is quiet and slow: a repository that clones without errors, opens without errors, and contains no game.

# 1. 初始化仓库
git init my-game
cd my-game

# 2. 确认 Git LFS 已经接进 Git
git lfs env
git lfs install

# 3. 检查忽略规则:路径 + -v 看命中的规则来源
git status --short
git check-ignore -v Assets/Art/Hero.psd
git check-ignore -v Assets/Scripts/PlayerController.cs

Two verification commands make this concrete rather than hopeful. git check-ignore -v with a path prints the matching pattern and which file it came from, so you can confirm both that a cache file is ignored and that a script is not. git status before the first commit shows you exactly what Git intends to track. Both take a second and prevent the two mistakes that cost the most time: committing a cache, and excluding real work. The broader question of how the resulting folder structure should be shaped is covered separately in the game asset management guide, and the engine-specific conventions for Unity indie development and Godot 4 indie development are worth reading before you settle on a layout, because the ignore rules and the directory structure are two halves of the same decision.

Git LFS indie game setup for large assets

Git LFS game assets setup is the part that makes the whole approach viable, and it is much smaller than it sounds. LFS works by changing what Git actually stores. When you stage a large file, a clean filter replaces its contents with a small pointer file that records the specification version, a sha256 oid identifying the real content, and the file size. That pointer is what enters the commit. The real bytes are uploaded to the LFS server and handed back to you on checkout by a smudge filter. The underlying mechanism is the gitattributes filter attribute, which pairs a clean command with a smudge command; the same mechanism is what makes text filters work.

# 一个被 LFS 跟踪的文件在 Git 里实际存的是指针:
version https://git-lfs.github.com/spec/v1
oid sha256:4cac19622fc3ada9c0fdeadb33f88f367b541f38b89102a3f1261ac81fd5bcb5
size 84977953

# 查看指针内容
cat .gitattributes
git show HEAD:Assets/Art/Hero.psd        # 看到的是指针,不是 80MB 的源文件

Configuring it means writing patterns into the .gitattributes file at the repository root. The command is git lfs track with one or more patterns, and the matching rules are the same ones .gitignore uses, so asterisks, question marks and brackets are wildcards unless you escape them. Two options matter for a game project. The --lockable flag makes matching files read-only in the working copy unless you have locked them, which is what you want for a shared source file that two people could otherwise open and overwrite at the same time. The --dry-run flag logs what would be written to .gitattributes and which files on disk would be touched, without performing any of it, and it is the correct way to preview a broad wildcard.

# 让 Git LFS 管理大体积素材
git lfs track "*.psd" "*.kra" "*.blend" "*.fbx"
git lfs track --lockable "*.blend"       # 多人协作时锁定源文件
git lfs track --dry-run "*.fbx"          # 预演:不写盘、不改属性

# ---- .gitattributes(由上面命令写入,必须提交)----
git add .gitattributes
git commit -m "track binary game assets with Git LFS"

# 验证
git lfs track              # 列出当前跟踪的模式
git lfs ls-files -s        # 列出 LFS 文件与大小
git lfs ls-files --all     # 扫全历史,找出漏网的二进制文件

Two details cause real friction. The quotes around the pattern are not optional: without them the shell may expand the asterisk before Git LFS sees it, and you will track a single literal filename by accident. And after any invocation of git lfs track or git lfs untrack you must commit the changed .gitattributes file. That requirement is explicit in the documentation, and skipping it produces the most confusing symptom in the whole tool: the pattern shows up in git lfs track output, the file is apparently being tracked, and yet the pointer is not being written. The rule is simple: the tracking rule is not in effect for anyone until the attributes file is committed.

Two more commands complete the picture. git lfs ls-files lists the LFS files found in the index and working tree, with -s to show sizes and --all to inspect the full history rather than only the current checkout - which is how you discover files that were committed before tracking was set up. git lfs lock and git lfs unlock talk to the LFS server and set a server-side lock on a path, so that pushes which modify a file locked by somebody else are rejected. Locking requires the file to exist in the working copy, and unlocking likewise requires the file to exist and to have a clean status, unless you pass --force.

# 多人协作:锁住源文件,防止同时改同一个 .blend / .psd
git lfs lock "Assets/Art/Hero.blend"
# 改完解锁(文件需存在且工作区干净,否则要 --force)
git lfs unlock "Assets/Art/Hero.blend"
git lfs unlock --force "Assets/Art/Hero.blend"

# 别人推了改动到锁定文件时,push 会被服务端拒绝
# 校验开关:lfs.<url>.locksverify

One more property of the design is worth understanding, because it explains the failure messages you will eventually hit. The gitattributes documentation notes that if the filter driver is not defined, or is not configured on a machine, the repository should still be usable: a filter that fails is a no-op passthrough rather than an error. That is why a clone on a machine without Git LFS installed still succeeds - you get pointer files instead of artwork, and the working tree looks wrong but nothing has crashed. There is a corresponding configuration that makes the filter mandatory, so that a missing LFS installation becomes a hard error instead of a silent surprise.

Commits, and the two commands that undo mistakes

A commit is a snapshot of the entire working tree plus a parent pointer, and the commit identifier is a hash of its content. That structure is why a commit is cheap to create and why the history is effectively immutable: changing the content changes the hash, so a modified commit is a different commit, not an edited one. That fact drives the whole recovery vocabulary.

git restore returns a file from the index to the working tree, undoing uncommitted changes. git revert creates a new commit that undoes an earlier one; it is safe on a shared branch because it adds history rather than rewriting it. git reset moves the branch pointer itself, and the mode decides how much survives: soft keeps the index and the working tree, mixed keeps the working tree but unstages, hard discards everything.

# 撤销工作区未提交的修改
git restore Assets/Scripts/PlayerController.cs
git restore --staged Assets/Scenes/Main.unity

# 已提交的改动:新增一个反向提交(不改写历史,适合共享分支)
git revert <commit-sha>

# 尚未推送:移动分支指针
git reset --soft HEAD~1     # 保留暂存区与工作区
git reset --mixed HEAD~1    # 保留工作区,取消暂存
git reset --hard HEAD~1     # 全部丢弃(慎用)

# 救命工具:reflog 记录了 HEAD 最近的位置
git reflog
git reset --hard <sha-from-reflog>

# 误删的分支
git branch <name> <sha-from-reflog>

The command that saves the day is git reflog. Git records where HEAD and your branches have pointed for weeks, which means that even a reset --hard is recoverable: read the reflog, find the hash of the commit you want back, and reset to it. The same log recovers a branch you deleted by accident before pushing it anywhere. Once you trust that path, you can commit more freely, and committing freely is what makes the history useful later.

Two habits are worth building deliberately. Stage specific paths with git add rather than adding everything, so a stray build artifact does not become part of a commit you cannot easily untangle. And commit only when the project builds, because a commit that does not build is a commit you will not want to reuse, and the whole value of a snapshot is that it is a state you would be willing to return to. If you are still choosing an engine, the game engine comparison covers how the two most common ones differ in project structure, which determines what your ignore rules and asset layout will look like.

A branching strategy that scales down

A Git branching strategy indie team rarely needs is a formal branching model with named branch types and release trains. What it needs is a small number of rules that everybody agrees on, and the rule that has survived the most projects is that a branch is a question and a merge is the answer. A long-lived main branch that is always releasable, a long-lived develop branch that collects the work, and short-lived feature branches that branch from develop and merge back into it. The cost of a branch is the merge, so branches that live for weeks accumulate conflict precisely in the files everybody is touching.

# 日常:在 main 上做小修复
git switch main
git pull

# 开发新功能:切出短期分支
git switch -c feature/player-dash
# ... 改代码 ...
git add -A
git commit -m "add player dash with cooldown"
git push -u origin feature/player-dash

# 改完合回 develop,再合回 main
git switch develop
git merge feature/player-dash
git switch main
git merge develop

# 清理已合并的分支
git branch -d feature/player-dash
git push origin --delete feature/player-dash

# 分支改名(连同 config 与 reflog 一起搬走)
git branch -M feature/player-dash feature/player-dash-v2

For a solo developer the same discipline applies in a reduced form: keep main clean, and use one scratch branch for the experiment you are not sure about, so that when it turns out badly you delete it without a merge. The tooling makes this cheap. git switch creates and switches in one step, removing the two-command dance that made Git feel heavier than it is, and git branch -M renames a branch while moving its configuration and reflog with it, which is the correct way to fix a branch name you got wrong after creating it. Git also lets you rename a remote-tracking branch the same way, which keeps the local and remote names from drifting apart.

The mistake to avoid is the opposite extreme, the long-lived feature branch that nobody can explain. If a branch has existed for more than a couple of weeks and nobody can state the question it is asking, delete it. The content is not lost if it was committed - it is still in the reflog and on the remote - and you have just avoided a merge that would have been painful for everyone.

GitHub for indie developers: remotes and pull requests

A remote is just a named URL, and adding one is a single command. The value of pushing to GitHub is threefold: the repository becomes a backup that is not on the machine that will eventually fail, it becomes a review surface, and it becomes something you can point at in a bug report. GitHub indie game repo best practices begin with getting the remote working and then tightening what is allowed to happen to the main branch.

# 连接 GitHub
git remote add origin https://github.com/<you>/my-game.git
git push -u origin main
git push -u origin develop

# Git LFS 用独立凭证(GitHub PAT,勾选 repo 权限)
# GitHub CLI 登录一次即可让 LFS 复用凭证
gh auth login

# 在 .gitattributes 里锁定共享源文件
git lfs track --lockable "*.blend"

# 建议在仓库设置里开启:
#   Settings → Branches → Add rule → main
#   ☑ Require a pull request before merging
#   ☑ Require status checks to pass

Git LFS on GitHub uses the credentials of the account you push with, which means that a personal access token with repository scope - or a single sign-on through the GitHub CLI - is all the authentication there is. If pushes succeed for regular files but fail for LFS objects, the credentials are the first thing to check, not the LFS configuration.

The review surface is where a small team gains the most. A pull request from a feature branch to develop or main gives you a place to read a diff, leave a comment, and see what the change actually did. Turning on branch protection for the main branch so that it requires a pull request to merge is a single settings change, and it is worth making even when the only reviewer is you a week later, because it forces the habit of reading your own diff before it lands. Branch protection can also require status checks to pass, which means a continuous integration run has to succeed before the merge is allowed. When a conflict does happen, resolve it deliberately, build the project locally, and commit the merge rather than leaving the work half-applied.

Size limits, quotas, and what LFS costs

Two separate sets of limits are in play, and conflating them is where most misunderstandings come from. For ordinary Git repositories, GitHub warns you when a file larger than 50 MiB is added and blocks files larger than 100 MiB outright; files uploaded through the browser are limited to 25 MiB. Git LFS is how you go past those, and it imposes its own per-file maximum that depends on the plan: 2 GB for GitHub Free and Pro accounts, 4 GB for Team, and 5 GB for GitHub Enterprise Cloud. A file above the per-file limit is rejected with an error rather than uploaded.

GitHub size limits and Git LFS allowances, as documented by GitHub
Limit Value What it applies to
Warning threshold50 MiBGit warns, but the push still succeeds
Hard block100 MiBFiles above this are rejected in normal Git
Browser upload25 MiBMaximum for a file added through the web interface
LFS per-file limit (Free / Pro)2 GBLargest single object accepted
LFS per-file limit (Team)4 GBLargest single object accepted
LFS per-file limit (Enterprise Cloud)5 GBLargest single object accepted
Included storage (Free / Pro)10 GiB per monthAccrues hourly, resets at the billing cycle start
Included bandwidth (Free / Pro)10 GiB per monthConsumed by clones and collaboration, resets at the cycle start
Included storage (Team / Enterprise)250 GiB per monthAccrues hourly, resets at the billing cycle start
Included bandwidth (Team / Enterprise)250 GiB per monthConsumed by clones and collaboration, resets at the cycle start

The two quotas behave differently, and the difference is the part most people get wrong. Bandwidth is measured against your free quota and resets at the start of each billing cycle, so it behaves like monthly fuel: how many bytes you move. The documentation states that there is no spending limit by default - the budget deleted state means there is no spending limit and you are billed for all usage beyond the free quota - so it is worth setting one deliberately if you want a hard ceiling. Storage is calculated from all Git LFS objects associated with the repository, regardless of when they were uploaded, and charges accrue continuously through the month based on hourly usage, with the accrued total resetting at the beginning of the billing cycle. Storage behaves like rent on everything you have ever kept.

For a solo developer with a few gigabytes of artwork, this is rarely the binding constraint. The practical constraint is usually that years of .blend and .psd history quietly exceed the allowance, and the fix is regular pruning plus an honest decision about what belongs in version control at all. It is worth knowing that you can choose whether LFS objects are included in the source code archives that GitHub generates for a repository, so a generated ZIP can carry pointer files only or carry the full objects. A related habit that pays for itself: track only the formats you actually author in, and let the engine's export format be produced from a build step rather than committed - which keeps the repository small and leaves the source file as the single source of truth. The asset management guide goes deeper on the naming and structure side of that decision.

How to use Git for indie game development, step by step

The seven steps below put the pieces above into the order you would actually perform them. Each step assumes the previous one is done.

  1. Step 1: Install Git and Git LFS, and confirm the environment

    Install Git and the Git LFS client, then confirm that Git LFS is actually wired into your Git installation rather than assuming it is. The check is git lfs env, which prints the current Git LFS environment. Run git lfs install once to set up the clean and smudge filters under the name lfs in your global Git configuration and to install the pre-push hook that uploads LFS objects, which by default is done for the repository you are currently inside. If you already have custom hooks and the install fails, the documented workaround is the --manual option, which prints instructions for merging the LFS functionality into your existing hook instead of overwriting it. If you work across several machines, remember that git lfs install configures the global Git config on the machine you ran it on, so every machine and every CI runner that clones your repository needs its own git lfs install. The --skip-smudge option is worth knowing about even if you do not use it every day: it skips the automatic downloading of objects on clone and pull, which is useful on a machine where you want to inspect the pointers without downloading gigabytes of artwork. The same behavior can be requested for a single command with the environment variable GIT_LFS_SKIP_SMUDGE, which skips the smudge process both in git lfs smudge and in git lfs filter-process when it is set to a truthy value.

  2. Step 2: Initialize the repository and write the ignore rules first

    Create the repository and write the .gitignore before the first commit, not after. Start with git init, then create the ignore file at the root of the repository and commit it as part of the initial commit. The contents depend on your engine. For Unity, exclude the Library, Temp, Logs, obj, Build and UserSettings folders along with the generated solution and project files. For Godot, exclude the .godot folder and the export output directories. The reasoning behind excluding the Library folder in particular is that it is a cache: everything in it can be regenerated by Unity from the source assets, so committing it multiplies the size of every commit for no benefit and creates constant merge noise. The corresponding rule for what you must keep is simple and absolute: the authored content is the repository. That means scenes, scripts, shaders, animation files, source artwork, the project settings file and the export presets all belong in Git. If you use a large binary source file that you will also want in version control, that is exactly what the next step is for. Before you commit, it is worth running git status to see what Git actually thinks you have, and git check-ignore with a path to confirm that a specific file is being ignored or not being ignored, which is the fastest way to verify the rules you think you wrote.

  3. Step 3: Track binary assets with Git LFS and commit the attributes file

    Now turn on Git LFS for the file types that would otherwise bloat the repository. Run git lfs track followed by the patterns for your project, for example git lfs track "*.psd" and git lfs track "*.blend", or a single command with both patterns. Use the --lockable flag for source files that multiple people might open at the same time, and use --dry-run first if you are applying a broad pattern such as a wildcard across a whole folder. Then commit the .gitattributes file, which is mandatory: the tracking rule does not take effect for anyone else until that file is committed. Verify the result with git lfs track, which lists the patterns currently tracked, and with git lfs ls-files, which shows the Git LFS files found in the index and the working tree; the -s flag shows the size of each object, and the -a flag inspects the full history of the repository rather than only the current checkout, which is how you find binary files that were committed before you set up tracking. One important property of the design is worth understanding: the large file itself is not stored in the Git object database. Git commits a small pointer file containing the specification version, a sha256 oid identifying the real content, and the file size, and the real bytes live on the LFS server. That is why the clean and smudge filter mechanism exists at all: the clean filter runs when you stage the file and replaces its content with the pointer, and the smudge filter runs on checkout and swaps the pointer back for the real file.

  4. Step 4: Make small, meaningful commits and learn the two undo commands

    Commit often, but commit things that make sense on their own, because a commit is the unit you will later want to revert, cherry-pick or bisect. Write the message for the person who will read it in six months, which is you, and describe what changed rather than that you changed something. Two habits separate a repository that is useful from one that is noise: stage deliberately with git add on specific paths instead of adding everything, so that an accidental cache file does not end up in the history; and commit only when the build is in a state you would be willing to hand to someone else. Learn the two recovery commands properly, because they are the difference between a five-minute mistake and a lost afternoon. git restore returns a file from the index to the working tree, undoing uncommitted changes. git revert creates a new commit that undoes an earlier one, which is the safe option on a shared branch because it does not rewrite history. git reset moves the branch pointer, and you choose how much to keep with the soft, mixed or hard mode. And git reflog is the safety net that makes even a hard reset recoverable, because Git records where HEAD has been for weeks. Once you trust that recovery path, you can commit more freely, which is the correct order of operations.

  5. Step 5: Create a branch and connect the repository to GitHub

    Push the repository to GitHub and start using branches for anything that is not a routine change. Create the remote repository on GitHub first, then add it with git remote add origin followed by the repository URL, and push the current branch with git push -u origin main so that the local branch tracks the remote one. From that point, git push and git pull work without arguments. To work on something specific, create a branch with git switch -c and a descriptive name, which creates and switches in one step, and push it with git push -u origin and the branch name the first time. When you are finished, the branch is deleted on the remote with git push origin --delete and the branch name after it has been merged. GitHub for indie developers is not only a backup; it is a review surface, and the review surface is what turns a solo project into a project other people can contribute to. The same directory structure and ignore rules apply to the repository you push, which is worth remembering if you also keep project documentation on the site: the repository and the published pages are two separate surfaces with different rules.

  6. Step 6: Protect the main branch and use pull requests

    A pull request is a proposal plus a review plus a place where the conversation happens, and for a small team it is worth enabling even if the only reviewer is yourself a week later. On GitHub, open a pull request from your feature branch to the development or main branch, and configure the repository so that the main branch requires a pull request before merging. Branch protection rules can require a status check to pass, require that branches be up to date before merging, and restrict who is allowed to push directly. GitHub indie game repo best practices start here, because the point of the rule is to make it structurally impossible to push a broken build to the branch that everybody plays. Before merging, read the diff yourself rather than trusting the green checkmark, and if the change touches the build files or the export presets, build it locally first, because CI will catch most things but not all of them. When a merge does conflict, resolve it deliberately, run the build, and commit the merge rather than leaving a stash of unresolved work lying around. For binary assets in particular, Git LFS has its own locking mechanism: git lfs lock with a path asks the LFS server to block other people from updating that path, and the file must exist in the working copy to be locked, which is why the --lockable tracking flag from the earlier step pairs naturally with it.

  7. Step 7: Migrate history into LFS and verify the repository is healthy

    The last step is the cleanup step, and it is the one people skip and then regret. If you committed large binary files before you set up tracking, the repository already contains those blobs in every commit that touched them, and the fix is git lfs migrate import, which rewrites the history to convert them into LFS pointers. This is the part of the workflow that needs the most care, because the tool is destructive by design: it rewrites commits and generates new commit hashes, so every collaborator must reclone, and any pull request that was open becomes invalid. The documented procedure is to commit or stash any uncommitted work first, run the migration, and then validate the result before pushing to remotes, for instance by running the info mode and by examining the rewritten history yourself. You can narrow what gets migrated with the include and exclude flags. If the repository has not been pushed anywhere and you want to avoid rewriting history altogether, there is a no-rewrite import sub-mode enabled by the --no-rewrite flag, which migrates the objects to pointers in a new commit without rewriting history, and which operates only on the current branch. When the migration is done, confirm the result with git lfs ls-files --all to see the objects across the full history and check the size of the repository on disk, because a repository whose history has been rewritten is a new repository in every practical sense.

Frequently asked questions

Is Git actually worth setting up for a solo indie game project?

Yes, and the reason is not that Git is good at remembering what you changed. It is that Git is good at letting you change your mind. A game project goes through a phase where you delete a whole character, rewrite the combat system, and rebuild the level editor, and in that phase a version control system is the difference between recovering in one command and reconstructing three weeks of work from memory. The second reason is that a Git repository is the cheapest possible backup that is already integrated into your workflow: every commit is a restorable snapshot, and if the repository is on GitHub, that snapshot also exists somewhere that is not the laptop that melted. The third reason is social rather than technical. Every engine tutorial, every bug report and every piece of community documentation assumes you can point at a specific commit. If you have never used Git, the moment you need help is the moment you cannot describe what you have. The counter-argument you will hear is that Git is complicated, and that is fair for about a week. The actual difficulty of Git for a game developer is not the branching model; it is that binary assets make the repository enormous and make every naive configuration slow. That problem has a specific, well-documented solution, Git LFS, and the rest of this guide is mostly about setting it up correctly.

How do I set up Git LFS for game assets like .psd and .blend files?

You write the patterns you want tracked into the .gitattributes file at the root of the repository, and you commit that file. The command is git lfs track followed by one or more patterns, for example git lfs track "*.psd". The patterns follow the same matching rules as .gitignore, so an asterisk, a question mark and the bracket characters are treated as wildcards; if you need to treat them literally, pass --filename and Git LFS will escape them for you. For a file whose name contains brackets, the documented example is git lfs track --filename "project [1].psd". There are two flags worth knowing about for a game project. The --lockable flag makes the matching files read-only in the working copy unless you have locked them, which is exactly what you want for a shared .psd or .blend source file that two people might otherwise overwrite simultaneously. And --dry-run shows what would be written to .gitattributes and which files on disk would be touched, without changing anything, which is the safe way to preview a broad pattern. Two things are easy to get wrong. First, the quotes around the pattern matter: without them your shell may expand the asterisk before Git LFS ever sees it. Second, and this is documented explicitly, after any invocation of git lfs track or git lfs untrack you must commit the changed .gitattributes file, or the tracking rule will not apply to anyone else. Git LFS writes the pattern into .gitattributes with a filter and diff specification, and the underlying mechanism is the gitattributes filter attribute, which defines a clean filter that runs when the file is staged and a smudge filter that runs when it is checked out. After tracking, the large file itself does not live in the Git object database. What gets committed is a small pointer file that records the version of the Git LFS specification, a sha256 oid identifying the real content, and the size of the file, and the actual bytes are uploaded to the LFS server and fetched on checkout.

What should I put in .gitignore for a Unity or Godot project, and what should never be ignored?

The rule is to ignore everything the engine can regenerate, and to commit everything that represents authored content. For Unity that means ignoring the Library folder, which holds imported assets and is fully derived from the rest of the project, the Temp folder, the Logs folder, the obj folder, the Build folder and the UserSettings folder, along with the generated solution and project files. For Godot it means ignoring the .godot folder, which is the import cache, and also the export output folders. What you must never ignore is the source assets themselves: the Assets folder in Unity, the scene files, the scripts, the shader files, the project settings file and the export presets. A .gitignore that accidentally excludes the Assets folder produces a repository that clones cleanly, opens without errors, and is completely empty of the actual game, which is the kind of failure that is only discovered weeks later. The matching rules in .gitignore are worth understanding because they are subtle: the order of precedence from highest to lowest is the per-directory .gitignore file, then the information exclude file at .git/info/exclude, then the file named by the core.excludesFile configuration variable, which defaults to the user's global ignore file. Within a single level of precedence, the last matching pattern decides the outcome, which is what makes negation work. A pattern prefixed with an exclamation mark re-includes a path that an earlier pattern excluded. One limitation is worth internalizing: it is not possible to re-include a file if one of its parent directories is excluded, because Git does not descend into excluded directories. That single rule explains most of the .gitignore confusion people run into, including the case where you exclude a directory and then cannot get one specific file inside it back.

What branching strategy should an indie game team use?

For most teams the honest answer is that you need fewer branches than you think, and the Git branching strategy indie team that works best is a long-lived main branch, a long-lived development branch, and short-lived feature branches that branch from development and merge back into it. The point of the extra layer is that main is always releasable, so there is always a known-good version of the game to roll back to. Feature branches should live for days, not weeks, because the cost of a branch is the merge, and a branch that lives for weeks accumulates conflict in exactly the files that everybody is touching. If you are working alone, the discipline still applies in a reduced form: keep main clean, and use one scratch branch for the experiment you are not sure about, so that when it turns out badly you can delete it without a merge. Git also gives you the tools to make this cheap. The git branch command with the -m or -M option renames a branch, moving its configuration and reflog with it, and the newer git switch command creates and switches branches in a single step, which removes the two-command checkout-then-branch dance that made Git feel heavier than it is. Whichever model you pick, the rule that matters most is that a branch is a question you are asking, and a merge is the answer. If a branch has existed for more than a couple of weeks and nobody can say what question it is asking, delete it.

What are GitHub's file size limits, and how much does Git LFS actually cost?

Two different limits are in play, and conflating them is the usual source of confusion. For ordinary Git repositories, GitHub warns you when you try to add a file larger than 50 MiB and blocks files larger than 100 MiB outright; if you add a file through the browser, the limit is 25 MiB. Git LFS is how you go past those limits, and it has its own per-file maximum that depends on your plan: 2 GB for GitHub Free and Pro accounts, 4 GB for Team, and 5 GB for GitHub Enterprise Cloud. A file above that per-file maximum is rejected by Git LFS with an error message rather than uploaded. The cost model is a quota rather than a flat fee. GitHub Free and Pro accounts include 10 GiB of storage and 10 GiB of bandwidth per month, and Team and Enterprise accounts include 250 GiB of each. The two quotas behave differently and that difference is worth internalizing. Bandwidth is measured against your free quota and resets at the start of each billing cycle, so it is a monthly throughput allowance that you consume by cloning and by serving the objects to collaborators. Storage is calculated from all Git LFS objects associated with the repository, regardless of when they were uploaded, and charges accrue continuously through the month based on hourly usage, with the accrued total resetting at the beginning of the billing cycle. So storage behaves like rent on everything you have ever kept, and bandwidth behaves like fuel for how often people pull. For a solo developer this is rarely the binding constraint; the practical constraint is that a game project with years of .blend and .psd history can quietly exceed a 10 GiB quota, and the fix is regular pruning and an honest decision about what belongs in version control at all. Another useful detail: you can choose whether LFS objects are included in the source code archives that GitHub generates for a repository, so a generated ZIP can either carry the pointer files only or carry the full objects.

How do I recover a file I deleted by mistake, or undo a bad commit?

Git keeps a history of every commit, and almost every beginner disaster is a single command away from being undone, provided you act before you create more commits on top. If you deleted a file but have not committed the deletion, git restore returns it from the index. If you already committed the deletion, git revert creates a new commit that undoes the change, which is safe on a shared branch because it adds history rather than rewriting it. If you committed the wrong thing and nobody else has pulled it yet, git reset with the soft, mixed or hard mode moves the branch pointer back and chooses how much of the working tree to keep; soft keeps both the staged and unstaged changes, mixed keeps the working tree but unstages, and hard throws away everything. The distinction that matters for a team is between rewriting history, which changes commit ids and breaks anyone who has already pulled, and adding a commit, which breaks nobody. The recovery tool that most people do not know about is the reflog. Git records where your HEAD and your branches have been for weeks, so even a hard reset is recoverable: run git reflog, find the entry for the commit you want, and reset to that hash. The same command fixes the case where you deleted a branch you had not pushed yet. For the specific mistake of committing a large binary file that should have been in Git LFS, the tool is git lfs migrate, which can rewrite history to convert those blobs into LFS pointers. The migration tool is explicitly described as destructive because it rewrites commits and generates new commit hashes, so the documentation says to commit or stash any uncommitted work before using it and to validate the result before pushing to remotes, for instance by running the info mode and examining the rewritten history. There is also a no-rewrite import sub-mode, enabled with --no-rewrite, which migrates the objects to pointers in a new commit without rewriting history at all, operating only on the current branch. For a solo project that has not pushed anywhere, the no-rewrite variant is the one to reach for.

最后更新:2026-11-15 · Facts verified against Git, Git LFS and GitHub official documentation on 2026-11-15.