Basic branching with Git (Unity example)
What is a branch in Git?
You can see a branch like a parallel work space in your project where you can work in a different feature, fix errors, do testing, etc. It allows you to have a main line of development and create others as you need them.
Using branches
Theses are the basic commands you need to work with branches:
- Create a branch:
git branch <branch-name>
- See existing branches:
git branch
Note: the name with the asterisk indicates the current branch
- Switching between branches:
git checkout <branch-name>
Basic merge:
Ok, there is a moment when you finish your work in one branch and you need to merge other branch, to do that just go to the branch where you want to add the changes and run the following command:
git merge <branch-name>
Note: When you run this command, you are pulling the branch that you type in the command to the current branch where you are working.
Unity project example:
- We have the “master” branch and we gonna create a cube:
- Now we gonna commit the changes and create a new branch called “color”:
- Switch to the branch “color”, create a material and add it to the cube:
- Finally I just switch to the “master” branch a do the merge:
And that’s all, you merge the work done in “color” into “master”