Current Goal: Making Websites

Git Basics

What it is

Version control systems such as git are a category of software tools that help a software team manage changes to source code over time.

Why it matters

Source control solves a bunch of problems around managing an evolving codebase. For example:

Save Points

At it’s simplest, git facilitates creating 'save points' in your code known as commits. If you get into a habit of committing your code into git frequently, you gain the peace of mind that no matter what breaking changes you make, you will easily be able to revert to where you were before without losing anything.

If you've ever tried to rewind hours worth of work, you'll know that "Undo" just doesn't cut it.

Remote Backups

Git has sophisticated tools for pushing and pulling your code from a remote server, or repository. Periodically uploading your code will prevent you from losing everything if your computer dies. There’s a plethora of free websites like GitHub and BitBucket that will allow you to save whatever code you want on their servers for free.


Imagine your team has multiple developers working on the same code at once. What happens when they change some of the same files? How do you combine the two people’s changes without poring over the code line by line? It becomes incredibly time consuming and dangerous to do manually. Git includes tools for automatically ‘merging’ multiple peoples’ changes together.

Multiple Copies

Another common problem is trying to maintain multiple versions of the same code. Generally, as you work on a project, you'll break everything, get it all working again, stabilize it for a release, and repeat. You generally want to keep track of the previous release of the code as well as a version with your most recent changes. Trying to maintain multiple versions of code by manually copying the folder quickly becomes an unwieldy nightmare. Source control solves this problem elegantly with branching.

To learn about some of the other capabilities and benefits of source control, read the Atlassian guide, What is version control?

For all of these reasons, learning and using source control is critical. Even for small projects: when I was learning to code, I made a cool chess engine as a resume stuffer. Unfortunately, my hard drive died and I lost the whole project. Explaining what happened in my first interview made me look foolish and inexperienced. Use git for everything, no excuses.

What you'll learn

  • What version control is
  • Why you need it
  • How to track and commit changes in git
  • How to save your code to GitHub

How to learn it

Git is an incredible tool that you will use every day. Unfortunately, it is notoriously confusing and difficult to learn.

"If it makes you feel any better, I use git EVERY DAY at work, and sometimes I'm like... how the hell do I do that again?" baubaugo on /r/learnprogramming{.caption}

Detached HEAD? rebase? Oh god. Mercurial, a leading source control competitor, is gaining traction by essentially being a slightly easier to use git clone. Still, since git dominates in popularity, so knowing it is mandatory.

Fortunately, you don’t need to completely master git for it to be useful to you. Use it as a means to an end.

We are still working solo, so it’s not necessary just yet to master branching and all of the tools for working together with a group. We’ll learn enough so that we can leverage it for remote backups and save points, and figure out what to do when it inevitably does something confusing.

Once we’ve had some exposure and have gotten into a comfortable rhythm of committing changes while we work, we can upgrade to using git’s more powerful capabilities.

What is git?

This short youtube series does a good job reviewing what git is and what it is for. The first two videos explain the basics, and the second two walk you through setting up git and a GitHub account. This is covered in the next part, so don’t bother: just watch the first two.

Note: He assumes you’ve never used the shell before, and suggests you move around by dragging in folders from finder. You don’t need to do that since you know how to navigate the filesystem with pwd, ls, and cd.

Getting started with git

Now that we get the idea, its time to learn how to actually use it. Work through Learn Enough Git to Be Dangerous. As always, don’t just read, follow along on your computer. Our goal for today is to understand how to make commits and push them to a GitHub repository, so stop before section 3.3 where he starts talking about branching.

By now, you should understand how to create a new GitHub project, make a series of changes and commit them, and push the changes back up to the remote repository. That is enough to get started!

When should you commit?

Making good commits is a skill that takes practice. Most people will simply work along, and then make a commit when they reach a natural stopping point or when they need to go home for the day.

This can result in commits that sloppily combine many different changes, or represent half-completed features. As you improve with git, you can learn how to use git rebase to combine multiple commits into one. Then, you can commit often to save your work, and when you finish a feature, squash all of the commits into one clean and descriptive commit.

Additionally, consider planning your commits upfront.


  • What is a version control system?
  • What is git? Why use git instead of one of it’s competitors?
  • What is Mercurial?
  • Why should you use source control?
  • What is a git repository?
  • What is the git working directory?
  • What is a git commit?
  • What is git staging?
  • What is GitHub? How is it distinct from git?
  • What are git pushing and pulling?
  • Where does git store all of a repository’s changes on your computer?
  • What is an untracked file in git?
  • How do you stage an untracked file in git? How about all untracked files?
  • How can you tell git to list the current set of changed files?
  • How do we tell git to commit the current set of staged changes?
  • What is the git command to see the commit history?
  • What git command lets us see the differences between the last commit and the set of unstaged changes?
  • What git command lets us see the differences between the last commit the changes we’ve already staged?
  • How often should you commit your changes to git?
  • What is special about the file "" on a GitHub repository?
  • What is markdown?
  • What is the command to push your changes to a remote git repository?
  • How can we tell git to ignore a file or directory?


To get a bit more practice and muscle memory with the commands, you can work through the Code Academy course on git. Just the first two sections for now.

From now on, even if not explicitly stated, get in the habit of using git with all of the code you write. When we switch back to working on CSS layout, we’ll use git to hang on to our changes.

What happens if instead of editing a file, you rename or move it? What will git diff do? Test it out.

What's Next?

This site relies on your feedback! These lessons are free. Please take this 2 minute survey when you finish each lesson so I can make them better.

Current Goal: Making WebsitesNext Lesson: CSS Layout