My GameDevHQ Journey Day 5: Merging Git Branches
Objective: Add another Git Branch and merge it with an existing branch.
Yesterday we successfully added a branch, made some changes to it and pushed those changes to the Git repository. Today, we will add another branch and do the same. This time we are going to merge the current branch with the ongoing development.
With this version control example in Unity, it's become apparent our First-Person Shooter needs an inventory to keep track of items we’ve collected along the way. We now have to develop an inventory branch of our main code.
To start, we enter “git checkout inventory” on the command line to switch us to the inventory branch in Unity. At this point, the inventory branch has nothing. Using the “git merge dev” command, we merge the existing dev into the inventory branch.
Next, we added an inventory script to the inventory branch in Unity. Entering “git status” in Git shows that we have untracked files we need to add to the next commit.
By entering “git add .” we track our inventory script in Git. Entering “git status” shows the inventory files are staged and ready for commit. We have not pushed the files to the server yet and switching to the dev branch using “git checkout dev” shows the changes are not part of the dev branch.
On the dev branch we enter “git merge inventory.” Now we have included all the changes made in the inventory branch in the dev branch. But we still have not added the inventory changes to the main branch.
Since we’ve done all our testing in the dev branch, we can release this new version of our FPS. To do that, we enter “git checkout main” to switch to the main branch.
Once that’s done, we can now enter “git merge dev” to merge the dev branch with the main branch. Following that with entering “git push origin main” on the command line sends the changes made with the merge to the GitHub server. Looking at the main branch on Github shows the inventory has been added to the assets folder.
Tomorrow’s edition of my GameDevHQ Journey we will address Reverting or Resetting by Branch.