GitHub and Git Bash, Branch Example

To finish this topic, we make a practical example for better understanding.
In our project, create a new C# script, and call it DevBranch.

In Unity we have this

In Git Bash, switch branch to dev and look at status

Add everything

and commit

Now, in Git Bash simply switch to master branch

If we back to Unity, happen this

Click reload, and the script “vanish”.
This happen because we work on dev branch, not in master branch.
So every change made in that branch, remain only in that branch.

If now switch to inventory, and, for example, you have to add something new,
you need to grab the dev branch first and merge with inventory branch.

To do that, use the command
git merge dev
so you merge the dev branch in your branch (in this case, inventory branch)

Back to Unity, we now are in inventory branch and we have both scripts.
Now, we add another script, and call it Inventory.
Check the status, add everything and check status again

Now commit
git commit -m “Inventory added.”

IMPORTANT : until now, we made change in LOCAL, not on SERVER,
because we not push NOTHING yet.

Now, as we have been seen before, if we change from inventory to dev, in unity happen same thing, Invenory script not exist here.

So, we have to merge the inventory branch in the actual branch, which is the dev branch.

Check Unity, and we see Inventory script here.

Now, check the status, and push to the server from dev branch to origin.

And this is what happen on GitHub page

Work everything, but if we change form dev to master, we have nothing here, because remember : master branch is where is the final status of project,
dev is where we work.
So, to finish, merge the dev into master.

Check status, and push all.

Branch can be a little bit overwhelming and difficult, but with some try and practice is easy to understand and use it.

Always in love with programming, even if late (I'm already 39 years old) I decided to follow my dream! We will see how far my passion will take me!