Setup Git with Unity3d for Commercial Development — Part 4 Branching

Click Here for Part 3

There is a saying in development: Branch early Branch Often.

This is because branching in Git is one of the more sane ways to work in a large team on large commercial projects.

0*bcLA988eYZFhX_f6.png (800×453)
Your current branch is shown on the right in blue, and green with the command branch

Basic Commands

git branch
git branch dev
git switch dev

Now you can see above that I’ve typed these out with a few extra ‘git branch’ commands so you can see the dev branch being created and switched to.

If you check the blue text at the end, you can see after the switch we now are in (dev). This is just the basics of the command, but what’s so powerful about branching is what happens when we commit a change and swap back.

Testing out Branches

git status
git add dev.txt
git commit -m "testing branches"

Now let’s do something crazy.
Let’s switch back to our main branch with the command

git switch main

and behold the dev.txt file is gone.

dev.txt no longer in the project folder as we swapped to Main where it doesn’t exist

And if we switch to dev the dev.txt file will return!

Now the way this conceptually works if we wanted to recreate it with just Windows is if we copied the folder, added dev.txt to one, and just swapped between the two. But Git knows (dev) branch only has 1 unique file, so it knows it can borrow from the past commits or “Versions”.

And once you know how feature branch merging works, you can start to see the real power of Git when working with team members.

Feature Branching and Merging

So let’s

git switch --create player_health_UI dev

Ok, big command! But it’s actually two commands combined to save time. Lots of other shortcuts like this exists, a simple change to the above is replacing — create for the shorthand command -c

What the command above is doing

As the branch name applies, we’re now focused on a “Feature”. Adding the player_health_UI to the game. For this, I’m just going to upload a .png file to simulate that I did the work.

You can do any changes you want but if you want to follow along just make a healthbar.png and do your normal add and commit as shown below.

Finally, to merge we simply switch to the branch we want to receive the new changes, and then say which branch you want to merge

Feature Merged! HealthBar now in Dev!

Now if you forgot to push that’s ok, we can still push after merges! Even though we merged we want to make sure everything gets pushed up so we can track it on GitHub better, especially as you may do 2 or 3 commits within your “Feature branch” before you merge. As in real-world work you might spend a few days getting the player_health_UI feature just right before merging it into the dev branch.

git push origin player_health_UI
git push origin dev

And we’ve done a merge!

And the Git Tutorials are done for now,
Where to learn more

The biggest thing is just getting used to using Git.
If you really want to dig more though…

Atlassian has some great guides talking about different Git Workflow and different ways teams do things.

I personally like the Git Flow method, which is an evolution of the Feature Branching workflow. I like Git Flow as it’s all about being able to release builds frequently even if it’s only to a test server for internal QA.

Example of GitFlow below

Taken from the GitFlow article by Atlassian

Catch tomorrow’s tutorial as we dive into more C# and Unity3d code over the coming days.

An Austin TX Unity3d Developer with a unique background in marketing, design, & software development leading digital web agencies to success for the past decade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store