Facebook

How to use Git with Unity

by Liam Cubicle Published February 13, 2024

A Version Control System (VCS) is a source control for managing file changes. It records changes to files over time. A typical example of a VCS is Git. Git is an open-source tracking system for keeping track of file changes. Git allows multiple developers to collaborate on a project, each developer with his copy of the project. Each copy is known as a repository. Git tracks changes made to files within a repository and can merge or revert changes made by different people, enhancing collaborations.

As a Unity developer, integrating version control systems with your projects is recommended to enhance collaborations and manage changes you make to your files. Using Git with Unity is just like using Git with any other project.

In this article, you’ll be provided with a step-by-step guide on how to use Git with Unity;

Configure Git

The first thing you need to do is to install Git on your local computer (if you haven’t). You can just download the Git Installer from the official website here. Downloads are available for Windows, MacOS, and Linux. After a successful download, install it on your local computer by following the installation instructions.

After a successful installation, you have to configure your username and your email address on Git. Here’s how:

  1. Open the Git terminal on your computer
  2. Then, enter the prompt below to configure your username.
$ git config -global user.nameyour username

Change “your username” to the username or team name you want to use.
Next, enter the prompt below to configure your email

$ git config -global user.emailyour email

Change “your email” to the email you want to use.

Create a Git Repository

Now, you have configured your Git appropriately. The next thing to do is to set up a repository for your Unity project.

  1. Navigate to the root folder of your Unity project in the Git terminal. (The “cd” command will come in handy at this point.)
  2. Type git init to initialize a repository.

Create a .gitignore file

Unity generates a lot of files that don’t need to be tracked by Git. Therefore a .gitignore file is needed to tell Git the files to be ignored and not to be included in the repository. The file cannot be created in the root folder of your Unity project. Files and folders you want Git to ignore are added to the file.

Add and Commit Files with Git

To make a commit, you have to first add the files and folders. To do this, use the command git add folderorfilename to add a file or folder. You can also use git add . to add all the files and folders at once.

You can use the git status command to check if you added the files.

Then, make a commit to the repository by typing the code below in the terminal;

git commit -myour commit message

It’s necessary for you to add a commit message. It doesn’t have to be long, just a short message that describes the commit.

Push and Pull changes

If you are working with a team, you will need to push your changes to a remote repository or pull changes from the remote repository on GitHub, GitLab, or Bitbucket to stay up-to-date with your team. Use git push to push your changes and git pull to pull changes from a repository.

Conclusion

Now, you have learned how to set up Git with Unity and even make your first commit. You should visit the Git documentation here for more information on using Git.

Free download: Indie Game Marketing Checklist

Download now

Category

programming

Don't forget to share this post!

Popular assets for Unity

See all assets ->
    Cutting-edge volumetric fog and volumetric lighting with support for transparent materials.
    Volumetric clouds, day night cycles, dynamic skies, global lighting, weather effects, and planets and moons.
    A lightweight procedural skybox ideal for semi-stylized projects.
    Image-based Outlines for 2D and 3D games with variable line weight, color, and displacement options.
    Per-pixel gaussian blur on your entire screen, part of the UI, or in-scene objects.
    Drag-and-drop ready-to-use ambient, impact, and spell particle effects.

Free Indie Game Marketing Checklist

Learn how to make your game successful with this handy checklist.

Download for free