• Polycarbon Games

Unity 3D Tutorial | Sharing your game on Git for free

Updated: Aug 26



There are many reasons to use a repository to store your work. Foremost, it's simply the smart thing to do:

• Keeps you from losing work

• Makes it easy to collaborate

• Easy to use (once you begin to learn how to use Source Tree)

• It's free

*A little background to help you read the instruction*


Remote and Local


Think of a repository as a remote folder that stores a snapshot of the software. You copy that snapshot by cloning it to your workspace, and then you can make your changes within your workspace without having to worry about breaking anything within the remote folder. After you’re satisfied with the changes, you can update the snapshot with your changes. It is a very simple concept that is used to share a snapshot among several team Members. Commands

There are a few basic commands you use in order to interact with the repository. These are the basic commands we will use to work with our repository:

Clone copies the files into the local environment.

*think of it as downloading

Pull copies the files into your machine for processing. *think of it as downloading but different.

Push copies the changes in the local environment into the server copy.

*think of it as uploading

Merge combines the differences between what you have and what is currently in the snapshot

Stage prepares files to be uploaded to the repository


Environment


In order to save your work in a repository, you will need the following:

1. An account with a source-code repository. In this case https://gitlab.com/ ca (it's free)

2. Source Tree: https://www.sourcetreeapp.com/ (free software for your desktop created by Atlassian)

3. Your Unity game or software that you want to store "in the cloud"


Instructions


Create a repository


  1. navigate to your home page on gitlab

  2. select New Project

  3. type a new project name

  4. select Create Project




Clone the repository to your desktop


  1. Navigate to the project home on Gitlab

  2. Select Clone

  3. Copy the Clone with https text

  4. Open Source Tree application on your desktop device

  5. Click Clone on your home menu

  6. Paste the https text taken from step 3 into the clone address field (the top field)

  7. Select an empty folder where you want to store the project

  8. Give it a name

  9. Select Clone



Add custom .gitignore for your Unity game


For many reasons, you don't need to store all of the files on your local machine into the server. Because of this, there is a file named .gitignore. It is a configuration file that tells git to stop tracking files, so they won't need to be stored on the server. Git ignores files and the .gitignore text you see below is the configuration for Unity projects. Copy and paste the contents below to your .gitignore file as per the instructions:


  1. Inside the folder, you configured with Source Tree, create and edit an empty text file

  2. Copy and paste this text below and save


# begin copy and paste this into a .gitignore where your project resides # This .gitignore file should be placed at the root of your Unity project directory # # Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore # /[Ll]ibrary/ /[Tt]emp/ /[Oo]bj/ /[Bb]uild/ /[Bb]uilds/ /[Ll]ogs/ /[Uu]ser[Ss]ettings/ # MemoryCaptures can get excessive in size. # They also could contain extremely sensitive data /[Mm]emoryCaptures/ # Asset meta data should only be ignored when the corresponding asset is also ignored !/[Aa]ssets/**/*.meta # Uncomment this line if you wish to ignore the asset store tools plugin # /[Aa]ssets/AssetStoreTools* # Autogenerated Jetbrains Rider plugin /[Aa]ssets/Plugins/Editor/JetBrains* # Visual Studio cache directory .vs/ # Gradle cache directory .gradle/ # Autogenerated VS/MD/Consulo solution and project files ExportedObj/ .consulo/ *.csproj *.unityproj *.sln *.suo *.tmp *.user *.userprefs *.pidb *.booproj *.svd *.pdb *.mdb *.opendb *.VC.db # Unity3D generated meta files *.pidb.meta *.pdb.meta *.mdb.meta # Unity3D generated file on crash reports sysinfo.txt # Builds *.apk *.unitypackage # Crashlytics generated file crashlytics-build.properties # Packed Addressables /[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin* # Temporary auto-generated Android Assets /[Aa]ssets/[Ss]treamingAssets/aa.meta /[Aa]ssets/[Ss]treamingAssets/aa/*








Store your changes to the repository for the first time


Stage, Commit and Push


  1. Select Working Copy under File Status

  2. In the middle panel, select stage all

  3. In the text field, type in your comment

  4. Select commit

  5. Select Master

  6. Select Push

  7. Check master

  8. Select Push



Create the development branch


This creates a copy that everyone should download when they access this repository. You will copy this version to your workspace in following steps


  1. Under remotes, open the caret and right-select master - checkout origin-master

  2. Name the branch Development*

  3. Select OK



Create your workspace branch


  1. Under Branches, select DevelopmentBranch you created in the last step

  2. Select Branch

  3. Name the new branch LocalBranch

  4. Select OK



Make a change in your workspace


  1. Select LocalBranch

  2. Go to your project on your local environment and make a change. *In this example, I simply create a folder and a text file in the project.



Commit your changes to prepare upload: Step 1


*Stage and Commit


  1. Select Working Copy

  2. Select Stage All

  3. Type in a comment

  4. Select commit



Merge changes to prepare upload: Step 2


  1. double-click the Development Branch

  2. select Merge

  3. Select the Local Branch, select OK


Copy contents to the server Step 3: Push


  1. Select Push

  2. Select Development Branch

  3. Ensure that the remote branch is also DevelopmentBranch Select Push


Congratulations! You've just created your first repository. Edit and follow the above steps and never, ever lose your work!