- Git is a free and open source distributed version control system.
- GitHub is the place to share code (repositories) with friends, co-workers, classmates.
- Git can be used with any language or code environment, and works great with Unity.
Start here: Git & Github Desktop. Then, review the steps below to setup Unity + Git.
Skip 1-4 if you fork any of the class dig250-unity-* projects
- Create a new Unity project
- Track Unity project with Git
- Basic Unity + Git setup
- First commit and push the project to Github
- Set up Unity and Git for a team
- Team workflow tips
- Dealing with issues
- Advanced Setup with SmartMerge
- In Unity Hub, click "New Project"
- Select a template, name and location. These instructions will use the example name
dig250-final-projectand location/Users/username/Documents/Github/ - Unity will add a new project folder and files to your computer.
⚠️ Don't save git repositories, Unity projects, and other app files in cloud-synced folders
It is strongly advised not to save version control repositories (such as Git), Unity projects, or other development files in cloud-synced folders like OneDrive or Google Drive. This practice can lead to several problems:
- File Corruption and Synchronization Conflicts: Version control systems and development environments make frequent, rapid changes to many small files. Cloud services may struggle to sync these changes in real-time, leading to synchronization conflicts, incomplete file uploads, or repository corruption [1].
- Performance Issues: The continuous scanning and syncing performed by cloud services can significantly slow down your development environment and build processes [1].
- Wasted Bandwidth: Large binary files often found in game development (e.g., textures, audio clips) can consume significant bandwidth as the cloud service constantly re-uploads them [1].
Recommended Practices
- Instead of using general cloud-synced folders, use industry-standard solutions designed for development workflows:
- Remote Repositories: Use dedicated hosting services such as GitHub, GitLab, or Bitbucket to back up your Git repositories [1].
- Cloud Storage for Large Assets: For large binary assets in Unity projects, consider using a Git extension like Git LFS (Large File Storage) [1].
- Dedicated Backup Solutions: Use dedicated backup software for local project files that don't rely on real-time syncing.
- Find the project folder in Finder or Explorer. Click the dots and "Reveal in ..."
- Drag the folder into Github Desktop.
- Since it isn't yet, Github will prompt you to "create a repository" there.
Manual option to track Unity project with Git 🐢
- Use Terminal to
cdinto the Unity project folder:cd ~/Documents/dig250-final-project. Confirm you are in the project root directory and can see project folders like Assets:ls -la - Initialize the directory as a new Git repository:
git init - In Github Desktop, choose File > Add Local Repository and select the project folder. (Alternately, add the project with Github Command Line Tool:
github .)
- Add a Unity-specific
.gitignorefile to the project root:- This version also includes OS-specific ignore content.
- This one is also recommended.
- Do not let your OS append
.txtto the end of the file name. - You will know the
.gitignoreworks if you cannot not see the/Library/directory in Github Desktop > Changes.
- Unity > Edit > Unity Project Settings... >
- Editor > Asset Serialization > Mode =
Force Text(forces assets to save as plain text) - Version Control > Mode =
Visible Meta Files - Version Control > Unity Version Control > Unity VCS =
Disabled
- Editor > Asset Serialization > Mode =
- Install Git LFS (Large File Storage)
- Install Git LFS
brew install git-lfs(Mac version, requires Homebrew) (more instructions) - Change to your project directory and initialize
git lfs install - Add a
.gitattributesfile to make sure Unity and Git LFS work correctly
- Install Git LFS
In Github Desktop:
- Add a message (e.g.
Initial commit) and create your first commit. - Push to publish the repository online. Make it public for now.
- One team member should:
- Create the project with Git using the above instructions
- Add team members as "collaborators" in github.com repository Settings > Manage Access
- Then everyone in the team should:
- Ensure Unity, Git, and Github Desktop is installed on their computers
- Have a Github account
- Clone the team project:
- Go to your team repo page on github.com
- Click Code > Open with Github Desktop
- Confirm setup:
- Add or edit a test file in the project
- Commit your change and push to the repo.
- Everyone else, pull the changes.
- Communicate often with your teammates; establish rules at the beginning.
- Commit your work often, using descriptive names for the commits and branches for your work.
- Work in separate branches - this ensures you don’t pollute the
mainbranch. - Work in separate scenes - YAML files are not pretty, readable, or organized 🙄 When you do work in the same scene avoid reorganizing assets.
- Use prefabs as much as possible to prevent scene conflicts.
- More tips: http://madwomb.com/tutorials/GameDesign_UnityGithub.html
- Clear caches (local package cache, global package cache) in case of corrupted packages, and let Unity rebuild them the next time it resolves your dependencies.
- Clear the Library folder
- Delete your project's cache, located at /Library/PackageCache, to force the Package Manager to rebuild the caches and re-install them in your project.
SmartMerge allows for more control over scene merging
- Enable SmartMerge to handle merging of scenes (see below)
Unity comes with its own UnityYAMLMerge tool to make scene merges with Git go smoothly.
- Unity Manual: SmartMerge
- anacat/unity-mergetool
- Assumes you have Git, Unity Hub, Unity installed and have followed the setup instructions above
- Windows-specific paths can be found here
# Download a fallback merge tool, for example diffmerge
brew cask install diffmerge
# edit .git/config file
nano .git/config
# ... and link to merge tool
[merge]
tool = unityyamlmerge
[mergetool "unityyamlmerge"]
trustExitCode = false
cmd = '/Applications/Unity/Hub/Editor/2020.1.2f1/Unity.app/Contents/Tools/UnityYAMLMerge' merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED"Now, whenever you merge or rebase and a conflict appears, instead of manually fixing, open Git Shell/Bash and type the following command:
git mergetoolThe tool will then resolve those conflicts for you automatically. If you don't have a fallback tool, you'll just get a message stating this, but you'll still be able to resolve the conflitcs in your editor. Then to run git add . in order to save the changes made, and then git rebase --continue when rebasing or git merge --continue when merging.
- Switch into the branch and test that everything works
- Switch back to master branch and choose Branch > Merge into current branch ...
- Select the branch you want and SmartMerge should take care of everything
- If SmartMerge finds issues it will prompt you to open the default editor used to resolve the conflicts (in my case, Atom).
- Open each file in Atom and scroll to select which conflicting text to keep
- Choose Commit Merge when finished
(Perforce, which provides more automation but looks like a serious pain to set up)
- Unity Forum thread (dead?) and Reddit Thread
- The Perforce installation instructions mention "P4Connect" connect on the asset store but it does not exist
- Perforce and P4V seem extra complicated to setup, with the only benefit a GUI to complete the merging. They are available on homebrew using
brew cask install p4vandbrew cask install perforce
- Unity+Git
- Infallible Code How to Setup a Git Repository for a Unity Project (13:55) (2022)
- Brackeys How to use GitHub with Unity (7:26) (2017)
- Git+Github




