Let's Git Educated!

Version control was honestly one of the hardest concepts I've had to reason through in my experience as a computer science students. People explained it to me countless times, but I still felt like I was missing some sort of magical piece that would help me unlock its secrets. The ease with which people would pull and push code was alarming... how could I do that if I couldn't even remember the commands I needed to type in? What is GitHub? Is that different than Git? Where am I pushing code to?? This feeling of being overwhelmed is normal- let's fix it! :)

Why Version Control?

Before we dive in too deep, let's take a step back and discuss why we might want to use version control when working on projects. Imagine you're writing a haiku on a piece of paper about how much you love llamas and your first crack at it sounds like this:

llamas are funny

they are nice, soft to the touch,

and make me happy

With poetry like this, let's just say that E.E. Cummings better watch his back! You take a break from your hard work and come back a few hours later to rearrange some words in your Pulitzer-Prize-worthy masterpiece:

llamas are lovely

they are cute, soft to the touch,

and make me joyful

You wipe the sweat from your brow and gaze at the piece of art you titled "An Ode to Llamas." Suddenly, your messy younger brother trips and spills grape juice all over your poem, making the piece of paper completely illegible!! On the verge of tears, you try to remember the words and their placement in the poem, but not matter how hard you try, you just can't. Someone who had a far worse poem than you wins the Pulitzer Prize for poetry, and you spend the rest of your life being haunted by images of llamas.

Okay, okay. So maybe that's a bit of an overreaction, but wouldn't it be nice to somehow revert to a previous version of your poem? And what if you thought the first version of your poem had better word choice, but you just couldn't remember what words you used? This is where the beauty of version control comes in.

Version Control = A Life Saver

Every time you make a change to your code and record that change in whatever version control system you're using, you have a log or a history of changes that you can refer back to. This makes iterating on an idea easier because you know that if you mess something up, you can always revert back to a previously functional version.

three commitscommit is a fun word that means "a change made to code!" made by two contributors

Let's break down all the details contained within this snippet of code history which allow us to quickly view older versions of code:

Version control becomes especially useful when multiple people are working on projects with you- we could say that your brother was an (unhelpful!) contributor to your poem who made some changes that you weren't happy with. Using version control, you can revert the destruction of your poem, collect your Pulitzer, and retire to a llama sanctuary in Peru.

Local and Hosted Code

I've been using the phrase "version control" a lot, but this has been sort of an abstraction. What tools do we use to keep track of the history of our code? Some examples of version control systems are CVS, SVN, Git, Mercurial, and Bazaar. It's not important to know how to use all of these- just pick one! I have experience with Git, so that's what we'll dive into.

Some fast facts about Git:

We're gonna discuss the foundations of Git through the best possible way- another hypothetial situation! After winning your Pulitzer, poets from all around the world are trying to collaborate on your next poem. You agree to work with two other poets, but you've learned from your mistakes, so you force everyone to use Git.

You guys lay down some hard-hitting lines in a publically shared Google Doc:

the original dog poem

You can think of this Google Doc as the central code basecomplete body of source code for a given software program or application between the three of you. Everyone has access to it, and as of right now, this is the official status of the poem. Each person thinks the poem can be better if worked on longer, but also is tired of social interaction, so they all make a copy of the Google Doc and start working on their own iteration.

the central copy and the three copies that have been pulled from the central copy

Okay! Now we have four different copies of this poem floating around, even if it looks like we still only have one poem. Notice that each poet has their own individual copy that is separate from each others and from the master copy. Now let's say that you disagree- it's quite obvious to you that St. Bernards are better than samoyeds! If we make changes to our own copy (and don't commit them to the master copy), these changes will not be reflected in any of the other copies:

notice how we only changed our own copy!