Git For Dummies Round 1
Tags: github, beginners, programming, git
Published: 2022-09-24 07:37:19

My superhero mentor attempts to teach me the correct pronunciation of the "I" in git.

That's the least of my challenges.

The great challenge is to explain Git to my mom, who has taken an interest in my Elixir journey, hoping that his son will finally have a real job she can talk to her neighbors about without too much struggle. 

If you can explain it to mom, you understand it yourself.

Who in his right mind could understand a creature that has branches and is not a tree. Has forks and is not cutlery. Pushes and pulls and is not a girlfriend.

So far I understand the concept of repository pretty well: that is where my code _reposes_.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9es10bril6hjh28fywlr.gif)

AKA: _"Mom, imagine a place somewhere where all the code I write is stored and organized"_

-- _All of your code is in that repository?_

-- _Not all. I create one repository per project, like you have a closet for summer clothes, another one for winter clothes, another one for clothes to charity_

-- _Gotcha_ (this gives me hope)

-- _Wait for it. I need to initialize a repository when I am working with it. The instruction or command for this is `git init`, like you are in-it._

-- _Like when I open the summer clothes closet. I have initialized the Summer Clothes Repository and I am in-it._

Mom. Senior Engineer. Her LinkedIn page is being updated as I write these lines.

I am making progress. I explain that she doesn't just throw all clothes in there (that'd be my style). She has stages when working with the Summer Clothes repository.

-- _Imagine you go shopping and buy a nice summer shirt. Is that already in the Summer Clothes Repository?_

-- _Nope. But it is on the way._

-- _That is an **untracked change** in the closet. As far as the closet is concerned, it doesn't exist yet, but you are working on it._

-- _Go on_

-- _Mom, if you had a terminal window in your heart and I keyed `git status` you would tell me about that summer shirt. You would not tell me about what has not changed in the closet, but about what has changed, could change, or is about to change._

And this is where Git starts to resemble Jack Nicholson in As Good As It Gets.

The beast has a bit of an OCD attitude to change. It likes procedures and patterns to the point of needing therapy. But... thank God, because if it was up to me, that Summer Clothes Closet would soon resemble an LSD trip, which could be fun, but would not facilitate a peaceful (nor sustainable) domestic experience.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f1grf4d42mf3f3zphr8v.gif)

-- _Mom, you first DECIDE the shirt belongs there, and then you ACTUALLY put it there_

-- _I go through those processes organically. You need to break it down into each step, because computers are silly creatures that need short, understandeable commands... very much like you._

-- _That's why I may be suited for this after all. Back to business: when you decide the shirt belongs in the closet you STAGE it with `git add <shirt>`. When you put it in the closet you COMMIT it, with `git commit`._

-- _Yes, I could decide that I do not like that summer shirt after all, or gift it, or lose it... there are reasons why it wouldn't make it to the closet._

-- _That is the untracked change_

Mom starts rethinking her entire domestic ethos, and wonders if parenting and homemaking had been easier had she explained domestic duties in this fashion to the men in the household. 

On second thoughts... No, it wouldn't. I can hear the talk at home: _"are those dishes untracked, staged, or committed to the dishwasher?"_

-- _"Some are staged, and some committed. Any untracked dishes around the house?"__ 

-- _"Look in your dad's office. He is always leaving cups of coffee untracked. I always end up committing them for him."_ 

-- _"He likes to think as them as staged in his mind. Like he'll commit them later."_ 

-- _"Well, if he never commits them to the dishwasher repository, they are as good as untracked to me. They remain around the house forever."_

(We may have commitment issues...)

I break it to mom that it is good practice to add a message when we commit, because a bit of fanfare never hurt anyone. Mom would shout "Dishwasher ON!" or "Summer Clothes Done!", which I would do with `git commit -m "Dishwasher On!"`. Now we know. The repository knows. Even Jack Nicholson is satisfied. Everything is tracked, and clear, despite the rest of us developing OCD as a result of all of this.


#Branching out

My challenge here is to explain branches to mom. She lives in reality, where time cannot be turned around, and where changes we made cannot, for the most part, be undone. 

Most ex-girlfriends understand this... Some do not.

I ask her to imagine that everytime she commits something to the closet, or any other repository, Git takes an internal picture, makes a dot in the map, leaves a breadcrumb, holds onto that thought forever. 

Imagine each commit as a step on the journey to the final Summer Clothes Closet, and Git taking a picture of how everything was at the exact time of each step.

_Controlling_ doesn't even begin to define Git. You do not enjoy a git-like mind in your loved ones. Alas, I start to learn that the more git-OCD you develop, the better your life as a coder. There are books and online courses on how to develop this pathology in a systematic fashion. Proceed with care.

Exhibit A: https://git-scm.com/book/en/v2

Back to the main topic:

Git gives you the option to go back and forth through all the commits, check things out, revert back to a happier time. One can, literally, step back. One can ask git about each step of the way to Summer Closet Perfection wtih `git log`. 

Each step is kept in something like an inner picture that one can work with independently. And one can create those steps at will. Git calls them **a branch.**

-- _Why a branch?_ 

-- _No idea, mom. I guess it is because it departs from something original and foundational, like the trunk of a tree. The point is that you can look at all the steps on the way and work with them. You can also create your own version of the closet, without having to touch the original, main closet_

-- _Why would I do that?_

-- _To test things out without messing the real closet badly_

-- _So one version per commit, which you see with the `git log` thingy, and also the option to create my own branches, which I do how?_

-- _`git branch <branchname>`_

-- _I imagine I will have to tell Git which branch I am working on._

-- _Genius: `git checkout <branchname>` indeed_

-- _So... Let's say I am cooking brunch, and each commit is each step on the way: I add pepper, I throw oil to the pan... I could totally create a new branch to safely experiment with the amount of salt that hits the sweet spot (`git checkout -b salt-experiments`). Once I know the perfect amount of salt, I would commit that amount, go back to the main dish with absolute confidence. I guess I would have to tell Git to take the information from the salt-experiments branch into the main dish branch. I assume there will be something like a `git merge` or `git pull`_




![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2nsm3y8ors4a7n2ia6e9.gif)

Mom runs to her laptop to create her new blog "Branched Brunch", while I recover from her already intuiting `git merge`. 

Moms have superpowers. Have you noticed how they predict the weather better than AI machine learning models? I do not even know how to begin with merging and pulling. She just pushed me to the edge of my current understanding, and I fell into the abyss.

-- _Son, is there any way that I could create branches for my friends, let them experiment with different aspects of the recipe, and then evaluate and merge only the very best to create the perfect one?_



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/du4dhrvp1h4tt4tzakmv.gif)

It's just too much. I cannot yet put all of this together: remote versions of dishes, amount of guacamole version control, permissions for not letting Susie add vodka to the omelette... but mom: she _gits it_. I am not sure I do.

I leave the conversation humbled and go back to studying. Surely I need to return to this conversation. Next time, better prepared to face my worthy contender.

For the time being, I'll share a true story about my mom. She once received a call from social services, enquiring about her wellbeing and needs. The lady on the phone asked her: _"Do you use the new technologies in your daily life?"_. I had to giggle. She had just made a 25% profit in her Bitcoin and Ethereum wallet, and used the profit to blast through the car payments. Does she use the new technologies... She is a Cyborg.

git add .
git commit -m "Moms rock. Thanks for reading"


BigSpaces