Can Unity Projects Play Nice with GitHub?

There are two common problem that surface while following the 2D Game Development course work:
- GitHub rejects pushes > 100mb (which is quite common with projects that have game assets)
- Conflicts with master vs main branches

The following instructions proposes avoiding those two issues, entirely. (*)

There are so many ways git instructions could not fit your circumstances, so the caveat here is that this is intended for those participating the GameDev HQ Game Developer Internship 2020 who have already completed most of their 2D Game Development course. Please review for context if you feel this relates to your situation, as well.

These instructions assume you are familiar with git commands, are able to find your way around and
- have a account
- have installed git on your local machine
- have access to a Terminal (Mac OS X) or GitBash (Windows) command line interface
- have set your and global configuration on your local machine

If you haven’t yet done so after installing git, run the following in a Terminal or GitBash window:

$ git config - -global “your username”
$ git config — -global“your password”

  1. Create a new repository and select .gitignore for unity.

2. On your local machine’s Terminal (Mac OS X) or GitBash (Windows) window change dir to your Unity projects folder (if you don’t have one, go ahead and create one in you Documents folder)

$ cd Documents/GameDevHQ/

3. Copy the https link for your new remote repository (with the green Code dropdown, click on clipboard to copy) and create a clone of your remote repository on your local machine

$ git clone[my_username]/SpaceShooter2D.git

4. Change into the new folder that was created

$ cd SpaceShooter2D/

5. Check for git status and note that you are in the main (formerly master) branch

$ git status

On branch main
Your branch is up to date with ‘origin/main’.

Tip: Always check status after each git command. It will seem mundane at first but be assured, it will save you to make this a habit, really!

$ git remote -v
$ git remote - -v

Will show your your remote repo origin:
origin (fetch)
origin (push)

$ ls -a

Note the two files that GitHub created (and auto-pulled) and the .git folder where all repo management takes place:
./ ../ .git/ .gitignore

6. Add the GameDevHQ folder to the end of the .gitignore file and save it:

$ vi .gitignore

You may use an editor of your choice to do this via your Finder or File Explorer. You will need to reveal hidden files to see it.


If you are using Mac OS X, also add


7. If you don’t already have a Unity project, create one in the GameDevHQ folder (let’s call it Space_Shooter_2D), then Quit Unity after it completes.

8. Return to the GameDevHQ folder and copy the contents of your new Unity project to your new local repository.

Note: If you have an existing local Unity project
- remove files and folders not originally put in the project folder by Unity (i.e., unitypkg, documents, videos, etc.) and move all build folders to a Builds folder.
- If you have been experiencing git problems, go ahead and delete the .git folder and any leftover .git* files in your project’s folder, including .git folders and files in any of the sub folders.

$ cd ..
$ cp -pr Space_Shooter_2D/* SpaceShooter2D/
$ cd SpaceShooter2D/

Now your original Unity project (Space_Shooter_2D) is a backup, and we will be working in SPaceShooter2D.

$ ls -a1 ← the number “1” to see the hidden files and folders

See the Unity project files and folders. Folders and files in bold will be tracked in git and the rest will be ignored and left on your machine (will not push to your remote repo):


9. Examine the end of the .gitignore file to make sure the GameDevHQ folder entry exists, and add it if it is not.

$ tail .gitignore

10. Preparing to push local repo project to remote repo

Always check for clean status in white (same as above):

$ git status

You should see only three folders and a file or two in red.

Add the changed (recently added and changed files) to the local commit:

$ git add .

Check to see they were accepted and turned green:

$ git status

Commit those changes:

$ git commit -m “initial commit”

Check for clean status in white as above, plus indicating your local repo is one commit ahead:

$ git status

Only push clean status commits to your remote repo:

$ git push origin main

See that your repo is back to clean status (all caught up)

$ git status

See that your remote GitHub repo now has your basic Unity folders and files (This is an example remote repo, so yours would be named SpaceShooter2D):

This is an example remote repo, but yours would actually be named SpaceShooter2D.
This is an example remote repo, but yours would actually be named SpaceShooter2D.

There are many other ways to do this, however, the above avoids the large file error that requires additional intervention as well as the issues with master and main branch conflicts (the two main blocker for this internship).

If you wish to now switch to GitDesktop or other UI based git managers, you should be able to do that, or continue on with this command line interface per the lessons in the Git Crash Course (or other learning source).

An unconventional software developer's journey