What is Git and How does it work?

The versioning tool, git is really useful as it essentially provides unlimited undo for your sourcecode. You’ll likely see git in most roles as a web or software developer. This article is written for new developers who know they need to learn git and not much else about it.

What is Git?

Using Git effectively will be easier for you if you have a concrete definition of what git is. First off forget what you know about other versioning tools. Git stores things differently, and you need to know this to use it properly. The best way to explain this is found in the official git documentation:

Git thinks of its data like a set of snapshots of a miniature filesystem. Every time you commit, or save the state of your project in Git, it basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. To be efficient, if files have not changed, Git doesn’t store the file again, just a link to the previous identical file it has already stored. Git thinks about its data more like a stream of snapshots.

git checkin visualization

The Three States

There are only 3 states of being as far as git is concerned:committed, modified, and staged. Again, the official documentation describes it well:

Committed means that the data is safely stored in your local database. Modified means that you have changed the file but have not committed it to your database yet. Staged means that you have marked a modified file in its current version to go into your next commit snapshot.

This leads us to the three main sections of a Git project: the Git directory, the working directory, and the staging area.

The Git directory is where Git stores the metadata and object database for your project. This is the most important part of Git, and it is what is copied when you clone a repository from another computer.

The working directory is a single checkout of one version of the project. These files are pulled out of the compressed database in the Git directory and placed on disk for you to use or modify.

The staging area is a file, generally contained in your Git directory, that stores information about what will go into your next commit. It’s sometimes referred to as the “index”, but it’s also common to refer to it as the staging area.

Git 3 states

In Closing

For real kids, the best way to get good at git is to read the official documentation and follow its examples. You can find git’s official documentation at https://git-scm.com/doc

 

Date
Categories
Tags
Permalink
Status

Published:March 26, 2016

code

Bookmark the permalink

Post a comment or leave a trackback: Trackback URL


Leave a Reply

Please wait...

Subscribe

Want to be notified when a new article is published? Enter your email address and name below to be the first to know.