How to set up Git and Git-LFS in Unity

Masud Afsar
4 min readJan 14, 2019
using version control in the game development

The first question: Why Git?

Real game studios generally have multiple developers, artists, and a lot of other roles working simultaneously on a game. So to ensure there are no conflicts in the codes or game assets between them, they need to use a version control system like Git to track file changes. Additionally, they need to revert changes and go back to an older version of the game or develop each feature in a separate branch.

The second question: How to set up Git?

Now, let’s explain installing and configuring Git and Git-LFS

  • Download and install Git based on your platform (Mac, Windows)
  • Open Terminal (or git-bash in windows) and type this command to ensure it’s installed correctly:
$ git --version
git version 2.20.1
  • The first thing you should do after installing Git is to set your name and email address. This is important because every Git commit uses this information:
$ git config --global user.name "Your Name"
$ git config --global user.email "your Email Address"

After Git, now prepare to install two important extensions on it: First, Git-LFS to manage game assets and large files, then Git-Flow to manage branches and workflow.

  • Download and install Git-LFS on your platform and type this command in Terminal to ensure it’s installed correctly:
$ git lfs version
git-lfs/2.6.1 (GitHub; darwin amd64; go 1.11.2)
  • Install Git-Flow and type this command in Terminal to ensure it’s installed correctly:
$ git flow version
0.4.1

Git is now ready to be used in your project!

The third question: How to prepare Unity3D projects to use Git?

When you want to use Git in Unity projects, you must set some config on it and add several config files in your project.

  • Open Unity and select your project. Then go to Edit > Project settings > Editor from menu. In the opened window, set Version Control Mode on Visible Meta Files and Asset Serialization Mode on Force Text like this:
Unity editor setting to prepare using version control systems
  • If your team works on different platforms, it is better to set Line Endings For New Scripts Mode on Unix.
  • Now create .gitignore file in the root directory of your project to ignore auto-generated files and directories from Git tracking:
# OS auto-generated files
.DS_Store
*.db

# Unity3D auto-generated folders
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Uu]nityGenerated/
/[Ll]ocal[Cc]ache/

# Auto-generated Visual Studio or MonoDevelop solution and project files
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.apk
*.cd
.consulo/
*.svd
*.pdb
*.opendb

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta

# Unity3D Generated File On Crash Reports
sysinfo.txt

# Builds
*.apk
*.exe
*.unitypackage
  • Now you must set the behavior of the Git file tracker about the text or binary files in .gitattribute file:
## Unity ##

*.cs diff=csharp text
*.cginc text
*.shader text

*.mat merge=unityyamlmerge eol=lf
*.anim merge=unityyamlmerge eol=lf
*.unity merge=unityyamlmerge eol=lf
*.prefab merge=unityyamlmerge eol=lf
*.physicsMaterial2D merge=unityyamlmerge eol=lf
*.physicsMaterial merge=unityyamlmerge eol=lf
*.asset merge=unityyamlmerge eol=lf
*.meta merge=unityyamlmerge eol=lf
*.controller merge=unityyamlmerge eol=lf

## git-lfs ##

#Image
*.jpg filter=lfs diff=lfs merge=lfs -text
*.jpeg filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.gif filter=lfs diff=lfs merge=lfs -text
*.psd filter=lfs diff=lfs merge=lfs -text
*.ai filter=lfs diff=lfs merge=lfs -text

#Audio
*.mp3 filter=lfs diff=lfs merge=lfs -text
*.wav filter=lfs diff=lfs merge=lfs -text
*.ogg filter=lfs diff=lfs merge=lfs -text

#Video
*.mp4 filter=lfs diff=lfs merge=lfs -text
*.mov filter=lfs diff=lfs merge=lfs -text

#3D Object
*.FBX filter=lfs diff=lfs merge=lfs -text
*.fbx filter=lfs diff=lfs merge=lfs -text
*.blend filter=lfs diff=lfs merge=lfs -text
*.obj filter=lfs diff=lfs merge=lfs -text

#ETC
*.a filter=lfs diff=lfs merge=lfs -text
*.exr filter=lfs diff=lfs merge=lfs -text
*.tga filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.dll filter=lfs diff=lfs merge=lfs -text
*.unitypackage filter=lfs diff=lfs merge=lfs -text
*.aif filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.rns filter=lfs diff=lfs merge=lfs -text
*.reason filter=lfs diff=lfs merge=lfs -text
*.lxo filter=lfs diff=lfs merge=lfs -text

*.dgml binary
[Ll]ighting[Dd]ata.asset binary
  • Now, Git needs to be initialized. Type these commands in Terminal to initialize git in your project:
$ cd <your project path>
$ git init
Initialized empty Git repository in <your project path>/.git/
$ git lfs install
Updated git hooks.
Git LFS initialized.

Final question: Now what?!

Now your unity project is ready to be developed and maintained carefully as professional game studios. If you are a beginner in Git read this article to learn the basics command of Git

--

--

Masud Afsar

Software Engineer and Full-stack Web Developer - I'm eager to learn and talk about JavaScript, TypeScript, Software Architecture, and Clean code principles.