Working with Branches in Git

Jose Gil
3 min readMar 30, 2021

--

We use branches at Mooski Games to ensure consistency with our versions and gives our developers areas they can work on safely without cause issues with the main final published released version.

At Mooski Games, we create the following branches for all of our projects.

  • main — for the final published release
  • dev — for the developers to work in.

In our more extensive projects, we may create additional branches, which we call silo branches. This allows us to break down the game into functional we are worked working on. Some examples of silo branches are quests, enemies, weapons, etc

Creating Branches

To create a dev branch on a Mac, you open the Terminal App and enter the command.

git branch dev

Replace the name dev with whatever you want to call it.

Switching between branches

It is vital that the developer is working on the current branch while they are developing. It would be disastrous to be working on the main branch when they should be working on the dev branch.

To check which branch is active. The branch with an asterisk before it and green is the current branch.

git branch

To switch to the dev branch enter.

git switch dev

Working with branches

When working within a branch, you will need to merge the files from another branch to ensure your project is consistent. For example, if you are working on the quests branch, you may need to get the latest version of the dev branch. For this example, you would need to have the quests branch active.

git switch quests

Then merge the dev branch with the quests branch

git merge dev

If you want to merge your quests branch back into the dev branch after modifications have been made, you will need to add and commit any changes you made to the quests branch before merging.

Add any files for the commit.

git add .

Commit any changes for that branch with a descriptive message

git commit -m “message”

Switch the dev branch

git switch dev

Then merge the quests branch with dev

git merge quests

Don’t forget to push the changes back to GitHub

git push origin dev

We use the same process outlined above to update the main repository.

Revert your project to a previous commit

There are two ways of going back in time in your project. You can revert or reset. We never reset and we will not go through that process here. We always choose to revert as it a safer process.

Before we revert a project to a previous commit, we always check to see if it is the correct commit to revert too. To review the commits, you can type the following command from within the specific branch

git log

Now find the commit you want to restore and copy the commit code after the word commit.

Now you can check out that commit and review if it is the correct one to restore. Press “q” to exit the log, then enter git checkout “commit code your copied”. For example

git checkout 723ed86ee0f46a8f1a0dc3cb8842cc8736fb16d5

Review your project and determine if you want to restore it. After you review it, you can exit that check out by entering

git switch -

or you can create a new branch to work from by entering.

git switch -c new-branch-name

Alternatively you can create new branch from the old commit without checking it out. This is done by entering git switch -c new-branch-name “commit code you copied”

git switch -c new-branch-name 723ed86ee0f46a8f1a0dc3cb8842cc8736fb16d5

We hope this guide on Git branches helps you with your next project.

--

--

Jose Gil
Jose Gil

Written by Jose Gil

Unity Developer at Mooski Games

No responses yet