Let’s Git Started: A Beginner’s Guide to Version Control Software

This blog is part of a continuous series that highlights experiences, insights, and tutorials from learning developers at Flatiron School in Web and iOS.  What is version control? Simply put, version control is collaborative history tracking. This means if a group of people are working on a project — be it software or otherwise — they […]

Reading Time 3 mins

This blog is part of a continuous series that highlights experiences, insights, and tutorials from learning developers at Flatiron School in Web and iOS. 

What is version control?

Simply put, version control is collaborative history tracking. This means if a group of people are working on a project — be it software or otherwise — they can use version control to track their progress and modifications without overwriting each other. One person changes a font, someone else changes a paragraph, yet another person adds an imbedded video. Without version control, you would have to worry about one person overwriting another. However, with version control, all of your individual changes are recorded and can be merged together at a later date. For more information, check out the video below. Several popular VCSs include Perforce, Subversion, CVS, Bazaar, and of course Git. https://player.vimeo.com/video/41027679[/embed]

What is Git?

Git is the most popular version control software around. It was invented by Linus Torvalds, inventor of Linux. Most other VCSs store information as a list of file-based changes. Git stores data as a series of snapshots. Almost every operation in Git is local, meaning you don’t need to wait on a server. Most operations are instantaneous. Git snapshots are checksummed with a 40-character string of hexadecimal characters called a SHA-1 hash, so it's impossible to change the contents of a file or directory without Git knowing about it. Git really only adds data. It’s hard to erase data or do something undoable.

Git Structure

There are three states in Git: committed, modified, and staged. Committed means your data is stored in the database. Modified means you’ve made changes but they haven’t been committed to the database yet. Staged means you’ve marked a file to be committed on your next commit snapshot. There are three main elements to a Git project: the working directory, the staging area, and the .git directory (repository). The Git directory, also known as the repository, is where your metadata and object database is stored. It’s the most important part of Git and it’s what gets copied when you clone a repository. The working directory is the area you’re working with when you’re making changes to your files. It’s a single checkout of one version of the project. The files are pulled out of the Git directory and placed here for you to use, and the staging area is just a file that contains information about what will go into your commit.

Blog post image: 1.png

Basic Git workflow

  • Modify files in working directory

  • Stage files by adding a snapshot to the staging area

  • Commit, move the snapshot into your Git directory

Is it different from Github?

Github is a free online Git repository. It offers a GUI and a graphical client for Mac and PC. A simple comparison is this:

Git is to Github as email is to Gmail.

Commands

git init This means git initialize, running this command makes your directory into a Git repository. Before running this, your directory is just a folder.git help If you’re ever lost, type this. It brings up the most common git commands. You can also type git help SOME TERM to bring up specific help regarding SOME TERM. Note, replace SOME TERM with an actual git command like init or add.git status This let’s you know what’s up. It will tell you what files have been modified and what files are untracked.git add Use this command to tell Git which new files to start monitoring. Bonus You run git add . to add all files that are changed or new.git commit This commits our snapshot of changes to our Git repository.git branch If you’re making a bunch of changes or expect your changes to take a long time, you might want to create an offshoot of the Git repository by making a new branch. This will be separate from the main branch, and you can name it whatever you want — git branch NAME.git checkout This allows you to navigate between different branches, such as git checkout master or git checkout name``git merge This merges the changes you made in your separate branch with the main branch.git push Use this command to send your changes from your computer to Github.git pull This is the opposite of push, it copies down the latest version of your repository from Github.git clone PATH This copies an online repository from Github onto your local computer and into the path you list. This blog was originally published under the name“Pre-work Part I: Let's Git Started”by Austin Gimour. You can check out his blog, Austin's Coding Adventure, here.

Disclaimer: The information in this blog is current as of October 5, 2015. Current policies, offerings, procedures, and programs may differ.

About Flatiron School

More articles by Flatiron School

Related Resources