Pro Git Notes


This post include notes to Pro Git book.

Git Introduction

Git is a Distributed Version Control Systems (DVCSs).
Clients fully mirror the repository, including its full history.
Distributed Version Control
Git thinks about its data more like a stream of snapshots.

Three Main File States

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

State Description
Commited The data is safely stored in your local database.
Modified You have changed your file but have not committed it to your database yet.
Staged You have marked a modified file in its current version to go into your next commit snapshot.

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

Three Git Project Sections

Working tree, staging area and Git directory.

Section Description
Git directory Where Git stores the metadata and object database in your project. It is what you copied when you clone a repository from another computer.
Working tree A single check out of one version of the project. These files are pulled out of the compressed database in the Git directory and placed on disk for your use or modify.
Staging area A file, generally contained in your directory, that stores information about what will go into your next commit. Its technical name in Git parlance is “index“.

Basic Git Workflow:

  1. You modify files in your working three.
  2. You selectively stage just those changes you want to be part of your next commit, which adds only those changes to the 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 repository.

Installing Git

Reference: Installing Git

Git Config

Reference: First Time Git Setup

Git Basics

1 Getting a Repository

1.1 Initializing a Repository in an Existing Directory

Bash example:

cd %my_project%
git init

This creates a new sub-directory named .git that contains all of your necessary repository files – a git repository skeleton.

git add *.c
git add LICENSE
git commit -m 'initial project version'

1.2 Cloning an existing repository

Bash command:

git clone <url>

(1) creates a directory,
(2) initializes a .git directory inside it,
(3) pulls down all the data for that repository,
(4) and checks out a working copy of the latest version.