How I Learned Git


  • Share on Pinterest

Last night, after several frustrating nights of tutorial hell, Git finally clicked for me.

I thought I would never get there; the imposter syndrome was eating me alive.

It reminded me of high school, when I would stay up all night to finish a project that I should have been working on over the course of several weeks, but instead binged in 1-2 days until the night before the due date, working on my assignment until the sun came up.

Half asleep, clicking “Save” on my Word document for the last time would give my sleep-deprived body a rush of euphoria as the feeling of accomplishment flooded my brain with dopamine. The light at the end of the tunnel was finally here.

That’s exactly how it felt when I completed my 4th consecutive (simple) git workflow successfully: no errors or weird, unrecognizable messages. Instead, typing a command and having Git respond as expected confirmed what I couldn’t yet believe: yes, Art, you got it. Needless to say, I slept like a baby last night.

Hindsight is 20/20. This is how I would simplify the process for my old, Git-less self.. if I could go back in time:

STEP 1

Understand the Purpose of Git

Understanding why you’re learning Git will make the relatively steep learning curve feel much more  surmountable.

For a while now, I’ve understood the purpose of Git. The simplest, most relatable example I can think of to illustrate the usefulness of Git is as follows:

You’re writing an essay in Microsoft Word.

You write your first draft and save your document: draft.docx.

You go on your merry way and a few hours later you have another idea for how to start your essay in a more engaging way. But you don’t want to scrap your first draft completely since there is some good stuff in there you’d like to look back on. So you write your second draft and save it: draft2.docx.

Maybe you do this one or two more times. So you create a new folder named Essay and in your folder you store your current 4 total documents: draft.docx, draft2.docx, draft3.docx and draft4.docx.

Logical, right?

Well, thanks to Git—a version-control system—this method of saving drafts is laughably outdated.

Imagine instead of piling up different drafts on your computer—draft1.docx, draft2.docx, draft3.docx and draft4.docx—you just have one file: draft.docx.

Except there are different versions of that file: version 1, version 2, version 3 and version 4. And you don’t need to worry about each version clogging up your folder. Instead of opening up your draft3.docx, you just go back to version 3 of your draft.docx. That’s Git’s original, groundbreaking utility.

Now, it gets a little more complicated than that when you add Github into the mix, or when you learn everything else that Git can do (a lot). But for beginner’s sake: that’s it’s most basic, brilliantly original function.

STEP 2

Learn Only The Most Basic Commands

Git, I’ve learned, is like eating a tough steak. The only way for you to possibly eat it is by taking small, patient bites and chewing thoroughly. If you take on more than you can chew, you’ll choke.

Once you understand the original purpose of Git, there’s only 3 real commands that are necessary to fulfill that purpose: git init, git add and git commit.

Think of commands like magic spells. git init is like telling a folder: “you shall be version-controlled!” This will start tracking changes in that folder.

git init

To version-control your Essay folder that’s holding your drafts you want to make sure you go into that folder (using the command line) and type the command git init.

Fun fact: init is short for initialize.

Once you’ve initialized your folder into a version control system, it will notice when you make any changes: whether that’s adding new files to that folder or changing the existing files themselves.

So you open up your draft.docx, type up your next paragraph and save. Your version control system has noticed that change BUT you have to tell it when you’re done with that version.

git add filename

You’re not quite done yet, you still have your conclusion paragraph to go. You go eat dinner and then go back to work to finish up your first draft. You write your conclusive paragraph and finally: you’re ready to save your actual first draft.

Go into your folder using the command line and use git add draft.docx to add the changed file.

git commit -m "message"

Then to actually seal it as Version 1 of your draft you will have to use your git commit command. The command git commit actually has a neat feature: messages! You can add a short message describing the changes that you have made. In this case your message might simply be “draft 1”. Together with the message it looks like this:

git commit -m "draft 1"

In short:

Use git init to initialize your chosen folder as version-controlled.

Use git add draft.docx  or  git add .  (cool trick: using a period instead of the file name will choose everything currently in that folder) to add the changed content in your folder to your next saved version.

Use git commit -m "draft 1" to seal the deal.

Version 1 is now saved with the descriptive message: draft 1, letting you know it is your first draft.

STEP 3

Doing More With What You Already Know

By the end of Step 2, you already know Git’s most primal purpose and how to take advantage of it.

Now going forward if you save 3 more drafts you will be able to go back to your previous versions (commits) and work with them. So even though the only file in your Essay folder is technically your 4th version of draft.docx, with Git you can go back to version 1 and take a look at it, or bring it back from the dead if you so choose.

To do that you’ll want to learn a new command: git log.

Git log will show you all your commits along with it’s descriptive message. When you see the commit with the message “draft 1”, you know that’s the first draft. From there you can then open that commit and work with it.

Conclusion

Once you know the very basics:

1) why version-control systems (in this case, Git) are useful

2) how to harness it’s version-tracking power

3) how to sort through your saved versions

you can then move on to Git’s intermediate phase: collaborating with others, sharing your work and pushing it onto a cloud service like GitHub with a much nicer UI than the ugly command line.

In the meantime, make sure to practice the basics:

Initialize your folders with git init.

Add your changes with git add.

And seal the deal on your finalized saved version with:

git commit -m "insert message here".