Setup your Unity project with Git this way to avoid Git LFS Issues.

Suleiman Abdullah
5 min readAug 7, 2022

Objective: Git Setup with Unity project to avoid git LFS issues.

Before doing this download git lfs and install it on your machine.

The first step is to initialize our project with git, we do this by using the git init command.

Then create a cloud repo on GitHub and don’t forget to add the unity dot ignore file.

Now we need to connect the local project to the GitHub repo, we do this by copy GitHub repo URL and connecting the link in git using this command git remote add origin “Url”.

In the following step, we need to configure git Lfs, git version control has not been built to handle big files that's why we need git Lfs, we do this by the command “git lfs install”.

Note: Remember we initialize this after installing git lfs from the beginning I assume you have already installed the software so now we initialize it in the specific Unity project by using the command “git lfs install”.

initialize git lfs to our unity project

In the next step, we need to track large files, we use this command to do this git lfs track “* file name” star means all file names with that extension.

by doing this git will create .gitattribute to track those file

But as you guess unity has many large files doing one each time will cost minutes, so we do this by copying the “.gitattributes attributes and then pasting them into our “.gitattributes” in our project, these attributes are already defined by the developers on the internet.

Copy the dot git attribute and paste it to the local project

Note: The dot git attribute will have only one tracked file if you are following me from the beginning, mine has already had many attributes because am repeating the process that's why you see many attributes in the file.

here is a link for .gitattributes https://gist.github.com/bitinn/4a82d7dbdaff62163031d318c57cd62d

Time to download our cloud repo to the local project, we do this by this command git pull. This will only download but not merge to the local project.

Then we need to merge the download folder to the local project we do this by using the command git pull origin master.

Note: I have changed the Github default branch name to master, so you need to make sure you put the correct name of the GitHub branch when adding this command make sure the Github branch name match this command git pull origin main/master/whatever you have defined it.

To make sure our git ignore is working, let's check the status of some files like temp and logs, etc if are not shown it means those files are ignored by git. we do this by the command “git status”.

If I add all my files to be tracked I will get an error file name is too long this is due to my file name being too long. This happened due to window system limitations. If you didn't face this issue continue to the step when I run again this command “git add .” you don't have to follow this long name error solution.

Note: this may not have happened to you if you have used a short name.

We need to run this command to allow git to add a long file name, but if we run this command git config --system core.longpaths true normally the process will be denied.

We need to run git bash as Admin, then run this command again,

git config --system core.longpaths true and hit enter.

Now go back to our local project and add all of our files, using the command “git add .”

No error all files have been added.

Let's verify by using this command git status to make sure everything is added.

The next step is to commit we do this by this command git commit -m “message goes here” and hit enter.

The last step is to push the changes to GitHub, we do this by this command git push origin “main/any name your GitHub repo is defined”.

yeah it's finished no light data error is 100MB wooh

Got to GitHub and verify that everything went smoothly, you will notice I will adjust the branch option the reason is below the note.

Note: I didn't notice that I have changed the GitHub default name to master “why Suleiman ? I don't know”, so when I run “git push origin main” it created a new branch named main but for you, it won't create a new branch since GitHub by default branch is main.

I hope you have reached up here thank you for reading my article.

--

--

Suleiman Abdullah

Self taught Unity Developer, who is passion about making games ,and he loves Math For Game Development