Version Control for Unity using Git + SourceTree
To begin with this guide, ensure that Git and SourceTree are installed on your system.
Connecting to Gogs
Gogs is Lehigh University self hosted Git solution. It’s where Lehigh students can store their work remotely and access it from any machine via Git.
Login with your Lehigh credentials
Make sure Authentication Source is set to Lehigh LDAP
Setting up SourceTree
On the first screen that’s Registration, click Skip
Repeat the same as above for Install Tools
On the screen titled Preferences use the first part of your Lehigh email address as the Author name, e.g amv324. Secondly use your http://lehigh.edu email address as the Author email
Creating a Gogs Repository
Click the + button on the top then click on the New Repository option
Enter the name of your project (Be aware that the name of the repository will be the name of the folder it’s in whenever you clone it)
The Gogs repository will be referred to as the remote repository. It’s what’s stored on the server. You can push changes to it to update it and if you ever lose your work on your local computer, you can clone this repository to get the project at the state it was in during your last changes that you pushed.
Linking the Remote Gogs Repository to a local project on your system
Now we want to connect our unity project to the Gogs repository. To start, we will create a local repository with Sour.
Creating a Local Repository
Click on the create option then pick the folder to be your Unity project folder and make the name the same as that folder. Then click on Create
Click on Terminal and enter
git lfs install
in the terminal
You will now have a local repository that holds your Unity project on your system now. The next step is to link that local repository to your remote Gogs repository.
Linking the Local Repository to the Remote Repository
Click on the Settings cog then Remotes screen in settings. After, click on the add button
In the “Remote details” screen input, the Remote name as the name of your project on Gogs, URL / Path as the git HTTPS link to your project, and Username as your Gogs username
My Gogs Remote Repository Details: As you can see the name of the remote is “git-unity-test”
Then click on the newly linked remote and click OK
Adding a .gitignore and Pushing it to the Remote
A .gitignore file is vital for a Unity project to ensure that you aren’t pushing unnecessary meta files that Unity will create. This is a solid template .gitignore for Unity.
Download the linked .gitignore and save it to your Unity project folder. When you save it ensure you save it as having the type of all files, as show below
Next, rename the file to be .gitignore since it will save as gitignore
Now, let’s add the .gitignore by staging the file to our changes. Under Unstaged files, find your .gitingore file and click on the + icon on the right of it
Now let’s commit our changes by typing in a message such as “Add .gitignore” on the bottom right then click the button that reads Commit
Finally, let’s push our commit to the remote by clicking the button on the top toolbar that reads as Push. . Then sign in with your Lehigh credentials if asked to.
Make sure to check master(in most cases unless you are pushing to another branch). Then click on push
Now if you go back to your remote repository on Gogs, you will see your .gitignore and maybe a README.md(if you made one) will be in your repository!
You can now repeat steps 2-4 for other files within your project to save your entire Unity project via Git
Cloning a Remote Repository to your system
Now, let’s say you already saved your Unity project to Gogs but lost it on your computer. You can get your latest project from Gogs to your system with GitKraken by cloning the repository
Click on the clone icon and then enter the link to your project on the top box. The other boxes should be auto-filled, just make sure you are okay the folder where it will put your project
In Unity Hub, Click on Add>Add project from disk then select the cloned project. You will then be able to open your project with Unity Hub
Pulling changes from a repository
Before you can push changes to the remote, your local must have the newest changes from the remote. This is called pulling. Let’s learn how this work by making a file in our remote and fetching it our local cloned project.
Let’s start with adding a new file by clicking on New file
Edit that new file and name it README.md. Put whatever you want here and make a commit message then click on Commit Changes
Open your local repository in SourceTree. Your local folder for the project shouldn't have the README.md yet. Click on the Pull button
Now, if you check your the folder of your cloned repository, the README.md file will be in it. Pulling is how you can get changes from other people from the remote to your machine. Make sure to pull before pushing.
Tips For Working with others
Have a single main scene and separate work across different scene
Serialized data like a Unity scenes or blender models are very tricky to work with when multiple people are making changes.
Find a way to separate concerns of work, such as make a scene for each person in the project and they build the systems needed for the project and push their changes to that scene alone
Then someone can pull those new Unity objects and blender models to the main scene.
Avoid working on the same prefab, script, or Unity object
Merging can be very tricky, it’s best to not have to do it when it comes to game development projects
Discuss who’s going to work on what and when teamwork is needed, use a video call and screen share if multiple people need to touch the same script or game object
It can be very easy to undo someone’s work on a prefab when multiple people are interacting with the same prefab and adding new components to it.
Additional resources
This is a great guide for setting up Unity and Git with a GUI:
You can also learn more about the Git workflow here
For immediate help, contact the LTS Help Desk (Hours)
EWFM Library | Call: 610-758-4357 (8-HELP) | Text: 610-616-5910 | Chat | helpdesk@lehigh.edu
Submit a help request (login required)