Git Overview

Posted in Git
Tags:

Git is version control software that keeps track of changes that you make to files and directories, and it is especially good in keeping track of text changes that you make.

guthubGit thinks of its data like a set of snapshots of a mini-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.

Everything in Git is check-summed before it is stored and is then referred to by that checksum. This means it’s impossible to change the contents of any file or directory without Git knowing about it.

Git is most useful for people who are not afraid of command-line tools. There are graphical user interfaces that can be used with Git, but it is first and foremost a command-line tool which is part of why it stays so popular with programmers and developers who aren’t afraid of those command-line tools.

So it doesn’t really matter what language you’re working in, doesn’t matter of simple HTML or if you’re working in a compiled language, you can use Git to track the changes in your source code.

Three States

Git has three main states that your files can reside in: committed, modified, and staged.

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.

A Git Project

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 simple 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 becoming standard to refer to it as the staging area.

Git Workflow

  1. You modify files in your working directory.
  2. You stage the files, adding snapshots of them to your staging area.
  3. You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.

Installation

Download from the downloads link: http://git-scm.com/downloads

After installation you can check the version of Git installed with command:

All the basic commands in Git will work the same no matter what version you are using.

The first thing you should do when you install Git is to set your user name and e-mail address. This is important because every Git commit uses this information, and it’s immutably baked into the commits you pass around:

If you pass the --global option, you only need to do this once because Git will always use that information for anything you do on that system.

Sign Up with Github

Visit github.com and choose a username and password and then build your profile.

Create a Repository

This creates a new hidden subdirectory named .git  that contains all of your necessary repository files — a Git local repository skeleton which will eventually hold all of the history and version control information about that project.

Note: the name of our repository is not important.

If you want to start version-controlling existing files (as opposed to an empty directory), you should begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:

To learn the basics of  Git, watch this video by Mathew McCullough:

Reference: http://git-scm.com/docs

2 comments on “Git Overview
  1. Bernard Pardey says:

    Fantastic blog! Do you have any recommendations for aspiring writers?

    I’m hoping to start my own site soon but I’m a little lost on everything.
    Would you advise starting with a free platform like WordPress or go for a paid option? There are so many options out there that
    I’m totally confused .. Any suggestions? Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

*