Using GitHub with Unity
Git makes it easy to both collaborate with other people as well as maintain several versions of your projects.
The most common place to host your projects is GitHub https://github.com and below I will go through how to use the command line tool Git Bash to do your first upload to GitHub.
Start by downloading Git from https://git-scm.com/downloads and pick the version relevant to your operating system. This guide will go through using Git with Windows, so some steps might be different for you if you are using MacOS or Linux.
Log in on GitHub and create a new repository.
1. Add a suitable name for the project
2. If you want others to be able to see the project, ensure that it has been set to public
3. Unity specific files are not necessary to upload, so enable .gitignore and set it to Unity
4. It is often preferred, that the main branch is called ‘master’ and you will also see this in other guides. To prevent confusion, change the name to ‘master’ as it automatically defaults to ‘main’:
Open Git Bash and navigate to your Unity Project. You can do this either via command line or via File Explorer. Inside the folder, right click and select ‘Git Bash Here’:
Depending on the type of project you are working on, it can be worth separating external assets, such as image files and audio files to their own folder and link Git to the actual working space. This will prevent any large files to get uploaded and take up all the limited space:
To add Git to your project, run the command git init. If you have hidden files enabled, you will see the folder “.git” show up:
Open GitHub and grab the URL from you project:
To link your project with GitHub, run the command: git remote add origin “URL”
You can confirm the connection by running command: git remote -v
Run command git status to see which files are untracked (red colour) or tracked (green colour). Only tracked files will get added to the repository.
To set all files as tracked, run the command: git add .
Now that the files are tracked, they can get committed to the local repository by running command:
git commit -m “message”
The message can be anything, but best practise is to highlight what has been done in this commit.
The final step is to add the commit to GitHub which you do by running command:
git push origin “branch name”