Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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.

  1. Go to https://gogs.cc.lehigh.edu

  2. Login with your Lehigh credentials

  3. Make sure Authentication Source is set to Lehigh LDAP

Setting up SourceTree

  1. On the first screen that’s Registration, click Skip

  2. Repeat the same as above for Install Tools

  3. 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

  1. Click the + button on the top then click on the New Repository option

  2. 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

  1. 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

    ts-create.png

  2. Click on Terminal and enter git lfs install in the terminal

    lfs-install.png

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

  1. Click on the Settings cog then Remotes screen in settings. After, click on the add button

    add-remote.pngImage Removedadd-remote.pngImage Added
  2. 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

    gogs-name.pngImage Removedgogs-name.pngImage Added

    My Gogs Remote Repository Details: As you can see the name of the remote is “git-unity-test”

    remote-details.pngImage Removedadding-screen.pngImage Removedremote-details.pngImage Addedadding-screen.pngImage Added

    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.

  1. 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

    save-as-all-files.pngImage Removedsave-as-all-files.pngImage Added
    1. Next, rename the file to be .gitignore since it will save as gitignore

  2. 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

...

  1. 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

    commit.pngImage Removedcommit.pngImage Added

  2. 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.

    real-push.pngImage Removedreal-push.pngImage Added

  3. Make sure to check master(in most cases unless you are pushing to another branch). Then click on push

    final-push.pngImage Removedfinal-push.pngImage Added

    Now if you go back to your remote repository on Gogs, you will see your .gitignore and maybe a README.md(if you make made one) will be in your repository!

    updated-remote.pngImage Removedupdated-remote.pngImage Added

  4. 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

  1. 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

    clone-link.pngImage Removedclone-link.pngImage Added

    1. 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.

...

  1. Open your local repository in SourceTree. Your local folder for the project shouldn't have the README.md yet. Click on the Pull button

    pull-button.pngImage Removedpull-2.pngImage Removedpull-button.pngImage Addedpull-2.pngImage Added

    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

  1. Have a single main scene and separate work across different scene

    1. Serialized data like a Unity scenes or blender models are very tricky to work with when multiple people are making changes.

    2. 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

    3. Then someone can pull those new Unity objects and blender models to the main scene.

  2. Avoid working on the same prefab, script, or Unity object

    1. Merging can be very tricky, it’s best to not have to do it when it comes to game development projects

    2. 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

    3. 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: ​

...