DEV Community 👩‍💻👨‍💻

Cover image for Explaining Git to a 10 year old!
Jacky Kumar Shaw
Jacky Kumar Shaw

Posted on • Updated on

Explaining Git to a 10 year old!

Hi! If you are reading this it means you are a 10 year old. If you are not you can still read along to get some insight.

Now Git, according to the definition is a "Distributed Version Control System", which sounds heavy enough that any 10 year old can switch off their brain from even trying to understand it.
But here my motive is to make it as simple as it can possibly get, so that even a 10 year old starts talking things that most adults are confused with.

Let's say you have a GOD-GIFTED friend named Git, just like Nobita has Doraemon. This friend of yours is very good at keep track of things. Like he can recall exactly what all things he does each day from morning till night, he can say how many things in the house have been changed today and what has changed in those things as compared to how they were yesterday, and so on.
And like Nobita you thought of taking advantage of this friend of yours to keep track of your progress in your essay.

Now you asking Git to help you is ["git init"].

Now you started writing your essay in a page and asked Git to keep track of the changes that you make in that page. This is ["git add page.txt"]. So Git also has kept a blank page with him just like you have.

You wrote in your page "The Sun is a big ball of fire made up of Hydrogen and Oxygen". Immediately, Git notices that, in the beginning, both the pages(yours and his) were blank(and so the SAME), but now, there is some text in your page whereas my page is still blank, so changes must have occurred. Thus Git says, "Hey your page is modified". This is ["git status"].

Now if you ask Git, "Of course I know that my page has been modified Git, because I only did those modifications. But what I do not know is, what modifications have been made, because I am not as good as you in keeping track of the changes. So can you tell me what changes have been made?". Asking this is ["git diff"].

To that Git simply compares his page with your page and says "A line saying "The Sun is a big ball of fire made up of Hydrogen and Oxygen" has been added". Then Git asks you, "Do you want me to update my copy of the page, by putting in the changes you have made in your copy of the page?". ["Git asking this is git asking you to stage your modified file again"].

Now if you want to say "Yes, Please!" to Git, you have to say ["git add page.txt"]. The moment you say that, Git THROWS away his copy of the page and takes a xerox copy of your copy of the page and keeps it with himself as his currently held copy of the page.

Now Git asks you, "Hey can I make one more copy of my copy of the page and save it permanently so that if you mess up your copy of the page and also ask me to update my copy of the page with the mess you have done in your copy of the page by saying ["git add page.txt], thereby ultimately messing up my copy of the page as well (by making me throw away my correct copy of the page in order to keep a xerox of your messed up copy of the page as my currently held copy of the page)then, I will be able to help you undo the mess in your copy of the page by referring to the permanently kept correct copy of the page that I had previously kept aside safely?". Git asking this is same as git asking ["Commit the files in the staging area"].

And now if you want to say "Definitely do that Git!" then you have to say to git

["git commit -m "my-first-commit"].

After the commit, currently, your copy of the page, Git's currently held copy of the page, and the copy of the page kept for permanent storage most recently, are all exactly the same. Everything is well and good.

Now you sit for writing again. And you realise that what you have written was wrong, because Sun is not made of of Hydrogen and Oxygen, instead it is made up of Hydrogen and Nitrogen. So you edit your copy of the page by replacing "Oxygen" with "Nitrogen". Immediately Git says, "Hey you have made changes in your copy of the page, do you want me update my copy of the page as well with the changes you have made in your copy of the page?". This is nothing but git asking you ["Add the modified copy of your page in the staging area again"].

Now before saying "Yes, Please!" to Git by saying ["git add page.txt"] if you write ["git diff"] then Git will tell you, "Hey, in the place where "Oxygen" is written in my copy of the page, in the same place, in your copy of the page, "Nitrogen" is written."

Now you said ["git add page.txt"]. Immediately, Git THREW away his copy of the page which had "Oxygen" written in it. And took the xerox of your copy of the page where "Nitrogen" is written in place where "Oxygen" was written, and kept it with himself as his (Git's) currently held copy of the page.

Guess what ["git diff"] will give right now? If you said "Nothing", treat yourself with a cake today because you are well ahead all your classmates in knowing git. If you did not say "Nothing", you do realize the fact that currently Git's copy of the page and your copy of the page both have "Nitrogen", so they are exactly the same. Thus ["git diff"] shows nothing.

Now, as you might have guessed, you friend immediately asks again, "Hey can I again make a permanent copy of my currently held updated copy of the page, so that.....same story?". This is nothing but git asking you to commit the newly staged files.

But before you say to Git, "Definitely do that Git!" by saying ["git commit -m "my-second-commit"], you got blown away when your elder brother laughed wildly seeing your copy of the page and finding out that you think Sun is made up of Hydrogen and Nitrogen. You elder brother then enlightened you by saying the truth that Sun is made up of Hydrogen and Helium and not Nitrogen. So you immediately modified your copy of the page and in place of "Nitrogen", you wrote "Helium".

Now if you are following the story line till now, you know that now if you write ["git diff"], Git will tell you, "Hey, in the place where "Nitrogen" is written in my copy of the page, in the same place, in your copy of the page, "Helium" is written."

And now if you write ["git diff --staged"] then Git, instead of comparing your copy of the page with his copy of the page, will compare your copy of the page with the most recently stored permanent copy of the page, and will say, "Hey, in the place where "Oxygen" is written in lastly stored permanent copy of the page, in the same place, in your copy of the page, "Helium" is written."

All that is good. But you don't trust your elder brother. So don't want to keep the changes you made according to your brother, and you want to go back to what you had prior to your brother's interference. Now your friend Git will actually help you.

Currently your elder-brother-influenced-copy of the page has "Helium" in it. Your friend Git's copy of the page still has "Nitrogen" written in it, and why is that so? because you never did ["git add page.txt"] after modifying your copy according to your un-trustworthy brother. And the lastly stored permanent copy of the page still has "Oxygen" in it because you never committed anything after the my-first-commit.
Now you can either undo the changes in your copy of the page and make it same as the copy of the page currently held by your friend Git, by the command ["git checkout page.txt"].
Or if you want to undo the changes in your copy of the page and make it similar to the lastly saved permanent copy of the page, you have to first free the hands of your friend Git, because as long your friend is holding his own copy of the page, how can he go and take out the permanent copy of the page for your undoing purposes? So to set free the hands of your friend Git, you have to allow him to make a copy of his currently held copy of the page and store it permanently (i.e. you have to commit what's there in the staging area currently). So you did that by saying, ["git commit -m "my-second-commit"]. Now if you want to make your copy of the page same as the first committed copy of the page, then you have to know the secret code of that firstly committed copy of the page. To know the secret code, you just say to your friend Git, ["git log"]. Then Git, comes up with something like this for you:-
my-second-commit : <40 letter secret code>
my-first-commit : <40 letter secret code>
Now you just have to say to your friend Git that ["git checkout <40 letter secret code>"]. If you decide to go back to my-first-commit, then type in the secret code of my-first-commit, or if you want to go back to my-second-commit, then type in the secret code of my-second-commit. And watch your messed up copy of the page magically getting changed as if it has gone back in time using a Time Machine like the one Nobita has inside his study table drawer.

If you have understood till now, you are a smart 10 year old.
Congratulations! and you must get yourself anther cake just to mark the success of reading an entire blog about the most used and technology, at the mere age of 10.

Top comments (0)

Update Your DEV Experience Level:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. 🛠