How to Git in Unity- part 4

S.J. Jason Liu
3 min readApr 24, 2021

--

Previous article: How to Git in Unity- part 3

Since we successfully connected our local files to github, now we can use branch.

Branches are commonly using for different part in a project. For example, if your team are in develop with a racing game, there might a branch for modeling, car function scripting, or game system building. Branch can help each part or group to develop alone but also can be merged when in need.

To create and switch between branches by the following steps:

  1. Name your new branch in console:
    git branch <branch name>
  2. Switch to new branch by using switch or checkout:
    git switch/checkout <branch name>
  3. Your current branch will show on the right in blue.
create new branch dev and switch to it

4. We can create multiple branches and check all the branches:

create multiple branches

5. While we switch to new branch and make some changes.

switch to branch dev
create a new script named DevScript

6. Add the changes and commit to new branch.

add all the changes and commit

7. Then switch back to main and you’ll notice the script is gone.

switch back to main
the change is gone in main

Now we have multiple branches with different process, we can use merge to stick them together. When a work is reaching some big section, such as prepare for publish or release the alpha version. Use merge to collect all the works is fast and easy.

1.Switch to the branch that you want to create something.

switch to new branch inventory
add another script

2. Add all the changes and commit.

add all the changes and commit

3. Switch back to the branch which we want to merge others in by using:
git merge <branch name>

merge inventory to dev

4. We can push our new branch.

push dev as a new branch to origin

5. Now you got 2 branches as I do.

2 branches now!

Next: How to Git in Unity- part 5

--

--

S.J. Jason Liu
S.J. Jason Liu

Written by S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

No responses yet