Setup your Unity project with Git this way to avoid Git LFS Issues.
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”.
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.
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.
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 this 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, we 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 this command “git add .”
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”.
Got to Github and verify if 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.