Branching with Git, the multiverse theory!...

Written by Abderraouf GATTAL. You should follow him on Twitter.
2019-10-09

TwitterTwitterLinkedInGitHubDribbbleBehanceMedium

Image for post

One universe or multiverses, in Git it’s all your call…

Git as a Universe is something I explained in my first Article Git, an entire universe to explore which you should take a look into it if you didn’t already, yet that didn’t cover it all somehow. In this article we’ll dive deeper in this concept and take a look on how much similar Git is to Universes and understanding what it really is.

What is Branching ?

Image for post

We may move in different circles but we all dance the same dance on the music of the spheres.

Branching is like creating a new universe based on the current one, a universe that respects the same laws yet still an entirely separate one, that can witness things no other universe would do. Well that’s too philosophic so in order to simplify we’ll say it’s just creating a new branch in the great tree of universes.

What’s a Branch ?

There are all types of universe in the multiverse but never the same universe twice.

A branch in Git is simply a universe that witnesses the actions saved on the commits we save. The default branch name in Git is master. Every time you commit, something in the selected universe changes automatically.

What’s a HEAD ?

To awaken quite alone in a strange parallel universe is the priceless moment to a time traveler!

A HEAD is a reference to the last commit in the currently check-out branch or universe. It is also the time traveler between universes (branches), the pointer that the developer can use to move from branch to branch and even from commit to another.
It is possible for HEAD to refer to a specific revision that is not associated with a branch name (a free series of commits). This situation is called a detached HEAD.

Image for post

What is Merging ?

Image for post

Parallel lines meet at infinity.

Merging is combining multiple sequences of commits into one unified history. In the most frequent use cases, it’s combining two universes (branches) into one line of history which is the point where universes meet.

The Story of multiverses

Now it’s time to start diving in the real theory, how to apply all the concepts we learnt in our work:

A. Create a new Branch

As part of the branching process, to create a branch is the first thing to do and that happens in order to simplify the task of doing several things at the same times either on your own or with the help of someone else. It means, allowing the things to develop in separate universes.

Creating the branch just happens by executing the git branch command.

Creating Universes

B. Switch context

The git branch command creates new universes (branches) yet doesn’t allow you to travel from a universe (branch) to another. So in order to switch the context to the universe you wish you should use the command git checkout.

Time Travel

C. Integrate changes

After creating and working on several universes, the step of getting all the stuff done merged in one line of history and one universe becomes necessary, so it comes the role of the git merge command.

Merging the multiverses

THE END

The secrets of a Multiverse are infinite…

We just covered the basic workflow of some concepts that you should understand in order to work with git easily. Yet you should know the proper commands to do so which you can find with details (Mainly in the cheat sheets) in addition to some valuable resources in here.