Before starting, make sure Git is installed on your system. If it’s not, visit the Git downloads page and follow the instructions to install it.
Use the command line to navigate to your Unity project’s root directory. This is typically where your Assets
, ProjectSettings
, and Library
folders are located.
cd path/to/your/project
Replace path/to/your/project
with the path to your Unity project’s root directory.
Initialize a new Git repository and also add a readme in your project’s root directory using the following command:
git init --initial-branch=main
git switch -c main
touch README.md
git add README.md
git commit -m "add README"
This will create a new .git
directory in your project root.
Unity projects have many files and directories that should not be tracked by Git. You can tell Git to ignore these files by creating a .gitignore
file in your project root.
Create a new file named .gitignore
in your project root, and add the following:
/[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*
This .gitignore
file is a good starting point for most Unity projects.
Now you can add your project files to the Git repository and make your first commit. Use the following commands:
git add .
git commit -m "Initial commit"
Your Unity project is now under Git version control. Remember to commit your changes regularly as you work on your project.
See also:
After you have initialized your local Unity project for Git version control, you can upload it to GitLab. Here’s how:
Navigate to GitLab and sign in. Once you’re logged in, click on the ‘New project’ button. Enter a project name, choose the visibility level, and click ‘Create project’.
Go back to your command line. You need to add the GitLab repository as a “remote” repository for your local Git repository.
git remote add origin https://gitlab.tudelft.nl/<your_directory>/<your_repository_name>.git
Replace <your_directory>
with your GitLab directory and <your_repository_name>
with the name of the project you created on GitLab.
Use the following command to push your local repository to GitLab:
If you get permission denied errors, see here.
git push -u origin main
This command pushes your commits to the ‘main’ branch of the GitLab repository.
Your local Unity project is now synchronized with GitLab.