Branching a Unity Project for Easy Collaboration with Git

Alberto Garcia
4 min readOct 21, 2022

--

Working on a Unity project with many people collaborating through different teams would be a huge hustle if each team had to share their developments through a flash drive, connecting each team’s drive into a central computer and get a functional prototype from that one computer. Luckily, tools like Git and File Base provide a version control system that allows collaborators to have a branch (or a version) of the project where they can work individually on their task. Branching early and often is advised as a great way to merge recent developments once they are functional for everyone on the team to keep working on top of them.

Here are the download links for Unity and Git. Unity works with the local files in your computer, and it can update to the different development stages of each creator by using the version of the project that is their branch. All of these branches belong to one repository that holds the entire project together in the cloud.

Once we have created a new Unity project, we’ll create our repository on GitHub; log in to your Git Hub account, go to your repositories and click the green button that reads “new”.

How to create a new repository on GitHub

Make sure to add “unity” to the .gitignore filter to avoid tracking unnecessary lists of templates. Adding a README file is always great to establish communication between collaborators editing the same project. Hit the “Create repository” button, navigate to that repository and on the right side click the green “code” button to find an “https” link to your new repository. Keep an eye on this one, we’ll copy/paste it in a bit.

Git Bash is a command-line interface to communicate between web sites such as GitHub and Unity, in our case. It simplifies the communication between GitHub and Unity. Let’s open up Git Bash and learn how to navigate around your computer through the interface, establish connection to the GitHub repository and create branches for an agile development.

Right-click inside project folder, show more options and select Git Bash Here

Git Bash will automatically open at that folder location.

Git Bash at project folder location

We now need to initialize and link Github to our local project. First we type in “git init” only when our command is typed at this folder location. Once the project has been initialized, we will copy that https link from our web repository to tell Git Bash that this is the folder we are linking to our remote server, in this case Git Hub. Now type in “git remote add origin [paste URL]”. “origin” is the standard name across the industry for the repository and after it we simply paste the copied URL by clicking the right-mouse button. Hit enter and you may verify by typing “git remote -v”.

With a linked repository, we may now start branching. To create a new branch simply type in “git branch [name]”, for example, try “git branch dev”. Let’s create a third branch called “prototype”: “git branch prototype”. If we just type in “git branch”, we will see a list with our branches and an asterisk next to the current branch we are using through Git Bash.

A list of our created branches

Switch from one branch to another by typing the command “git switch [branch name]” (“checkout” is another viable command). The name shown in blue parenthesis at the end of your directory address will confirm which branch you are currently using.

use switch / checkout to change current branch

Now that we have multiple branches in our repository, we may take one branch to experiment with a particular task in development without editing the main branch. This will help teams, and even indie developers, to work on creating new features for a project without altering the main project through that process. For more information on how to use Git Bash try reading the user manual.

--

--

Alberto Garcia
Alberto Garcia

No responses yet