Git branches explained

_config.yml

Source picture taken from here

What are Commits

You can think of commits as basically photographs of an event/person through different points in time.

But the photos and camera you are using are very special: they allow you to travel back and forth through time. In other words, if you had taken a photograph with that special camera, of a particular event in time – then you could return to that particular point in time. Basically you have a time machine. That’s basically what Git allows you to do.

What can you do with this?

Once you have the photo, you can basically go to a particular event/time period/point in a person’s life and do things. Imagine if you could go back in time, and actually change the future! What if you could convince Julius Caesar not to cross the Rubicon? What if you managed to convince Hannibal to immediately march on Rome after Cannae? You’d basically be changing the future.

Basically, so long as you have a photo – then you can go to that particular point in time.

The advantage of using this time machine is that you can go back in time, change the course of history, and then decide whether you like the results. Imagine you could go back in time and avert the US Civil War (1860-1865), and spare half a million deaths. Would the world be a better place? Well you won’t know unless you try. So you try. And you find out that slavery still exists and the world is a horrible place. No problem, you can simply use your time machine to go back in time to recreate a future which you do like.

Git Branches as a reference – Explained

Think of a photo album which shows hundreds of photos of the same person - say Freddie - through time, throughout his life.

  • 1: baby photo - 1 year old. (SHA: WJELKRJEI893024) - Born in Zanzibar
  • 2: photo - 2 years old (SHA: SDFKRJEI893024) - Moves to India
  • 3: photo: 18 years old (SHA: WESRJEI893024) - moves to England
  • 4: photo: 19 years old (SHA: BESRJEI893024) - forms a band
  • 5: photo: 19 years old (SHA: DGSRJEI893024) – hot space tour + talks with Michael Jackson about possibly doing Thriller with him
  • 6: photo: 39 years old (SHA: LDSRJEI893024) - steals the show at Wembley

Now imagine you can go back in time (using a DeLorean time machine) and talk to Freddie at exactly each stage of his life – when he was at different ages. You could listen to his music and talk to him as and when he finished an album - he would have all the answers pretty fresh in his mind. Pretty cool right?

If somebody asks you after you’ve travelled through time: hey, at what particular stage in Freddie’s life are you at right now? How would you answer that question. I’m at WESRJEI893024 won’t make much sense to a human being. That’s where branches and tags come in.

The next time you decide to interview Freddie instead of saying I’m at WESRJEI893024 – you can say instead: I’m at the point of time in Freddie’s life where he “moves to England”. That makes a whole lot more sense to people.

And that is what branches and tags basically do. Branches are merely a “reference to a commit”.

Ok so you go back in Time to Visit Freddie When During the HotSpace Tour

Remember you are a time traveller. You can go back and forth through time. You can possibly even change time itself by creating an alternative scenario. So you go back in time to talk to Freddie when he’s doing the hotspace tour. If somebody asks you were you are, then you could simply refer to the “hotspace tour” and everyone will know exactly what you mean.

But what if you decided to change the future, what if you managed to convince MJ and Freddie to go ahead with the Thriller collaboration? So they do Thriller together. You decide that this point in time is too good to be true, so you decide to make sure you can come back here.

What is a “reference to a commit”?

In other words, you can think of a branch as a white board. You can have many whiteboards in your “repository”. Each whiteboard has a name – e.g. “Shopping-List” which has written on it, a SHA of a particular commit. If you want you can erase the SHA on the white board and write another SHA on it. And of course, the SHA points to a commit. And once you have a commit – then you can access everything as it exists at that point of time.

What if you clear the white board?

If you clear the white board, that means you can no longer travel back in time to a particular commit using that branch. And if there are no white boards which point to that commit then the garbage collector will come and eliminate those commits in 90 days. The above paragraph might not make much sense to you. But hopefully you will have understood something from the first two paragraphs.

I hope this helps.

Written on July 30, 2017