Create GitHub repo for existing Unity project
Whenever I get my hands on new Unity assets, do quick tutorials or want to test some code I create a new project and go wild. Most of the time, these projects are abandoned and deleted when I’m done with them. However, once in a while I will write some valuable code or design cool mechanics that I want to save for future reference. In such a case I create a GitHub repo.
The process of adding a pre-existing project to GitHub is slightly different from a typical scenario in which you first create a GitHub repo for a project and only then start working on the project itself. This is why I am making this article as a sort of a cheat sheet. Note: I am using Windows 10 PC and GitHub Desktop for interfacing with GitHub.
1. The folder structure on your drive
Create the main folder for your project (Local Path). This main folder will contain 2 subfolders:
- .git folder for version control (created automatically by GitHub),
- your actual game folder, which you will copy there later on.
2. Create GitHub repo
This is where the project will be stored on GitHub. Click the + icon in the upper right corner of your GitHub account and choose New repository. Then fill out the form according to your needs and press Create repository.
Note: Don’t forget about adding a gitignore file, e.g. https://github.com/github/gitignore/blob/master/Unity.gitignore#.
3. Clone the GitHub repo in GitHub Desktop
In the GitHub Desktop application go to File > Clone repository. Choose one of the methods for cloning the repository. I use the URL method. For this you will need two things:
- The URL of the GitHub repo. You can copy it directly from GitHub.
- The Local Path.
This will create a repository structure in your Local Path. There will be a .git folder (for version control) and additional repository files like gitignore or readme.
Note: the local folder should be empty for the Clone operation.
4. Copy existing project folder to the repository in your Local Path
Find the project you wish to hook up with GitHub, copy the folder and paste it to your LocalPath. It should be on the same folder level as the .git folder.
If done correctly, your project is now part of the version control system. GitHub Desktop will detect new files and allow you to commit/push changes.
5. Remove old project from Unity Hub
You want to run the version controlled project in Unity Hub from now on. Therefore, remove the old project from the Hub.
6. Add version controlled project to Unity Hub
Add the new project location from Unity Hub. When prompted, provide the location of the project folder within the
You will now be able to run this new version controlled project from Unity Hub. Any changes will be reflected in version control.
Bonus: An informative and funny graphics about GitHub:
Recent Comments