Part 1 – Basic Concepts about Git

Let’s learn some basic concepts about Git

What is Git?

Git is a popular distributed version control system that’s widely used among programmers and developers for developing and maintaining code.

What is Version Control System?

It tracks the changes to projects over time automatically so that you can check progress or revert to an earlier version if required later. It helps prevent loosing your work from over writing or inadvertently deleting files.

There are two main types of version control software.

  1. Centralized:

A centralized version control system will maintain a central repository for project files that individuals can then check out to work on and then check back in when they’re finished.

If a file’s already checked out, in most centralized systems, they won’t allow other collaborators to work on it until that file has been checked back in, and this is to prevent files from being overwritten inadvertently. It helps maintain a single centralized repository for these project files. Popular centralized version control systems are Subversion and CVS.

In a centralized system, the failure of the remote server could mean the loss of all of those project files.

  1. Distributed:

In distributed version control systems, each client keeps a local mirror of the project repository. Depending upon how the work flow is established, individuals can either push changes to other repositories, pull changes from other repositories, or synch changes between multiple repositories. The value of this distributed approach is that if any of the individual mirrors are lost, simply cloning another client can restore them. It also allows more freedom among collaborators, as they’re free to work on changes individually, and then push those changes to the remote repository when it’s appropriate.

How Git works?

Git works by taking snap shots of your project each time when you save its current state. Current state is saved by making what is known as a commit. If a file’s changed, it’s included as part of the snapshot. If it’s not, a reference to the earlier file is used. Going back to an earlier commit simply restores the file system to one of these earlier snapshots.

What happens when you initialize a Git repository?

When you initialize a Git repository, a Git directory is created inside of your project that contains all of the metadata and the database necessary for tracking that particular project. This repository is also referred to as a ‘repo’.

Basic areas of any project:

When you initialize a git repo, it establishes the three basic areas of your project:

  1. Working directory: Working directory contains the current state of your files and that’s going to be based on the current commit that you have.
  1. The staging area: The staging area contains an index that’s going to be contained in your next commit, which is usually the files that have been added or modified since the previous commit.
  1. The Git repository: Once the commit is made, the commit is added to the git repository.

 And the process starts all over again.

States of any Git File:

Each file that git tracks exists in one of three states:

Unmodified: if a file hasn’t been changed since the last commit, it’s seen as unmodified and won’t be added when you do your next commit.

Modified: If a file has been changed since the last commit, it is seen as modified, meaning that it’s available to be part of the next commit. This doesn’t happen automatically. To add a modified file to a commit, it must first be staged.

Staged: Staging a file simply moves it into position to be added to the next commit.

This creates a workflow where files are modified, staged, and then saved as part of a commit. It allows you to choose which modified files to add to every single commit you make. It allows you to, for example, experiment with a file for a little bit and only add it to a commit when it’s ready.

Git Branches:

One of Git’s most powerful features is its ability to create branches. At any point, you can take an individual commit and create a new branch from it. You can then develop and experiment with this branch without affecting your master branch. This can either be spun off into a separate project, or you can even merge it back into the master branch and add all of these changes.

Now you have learned basic Git concepts, it is the time to install Git on your machine.

Installing Git on your windows machine

You can install from windows.github.com. Just follow the installation directions provided by installer and you are done!

Want to learn more? Check out Lesson 2 – Git Basics – Creating and Initializing a Repository

Article written by

Please comment with your real name using good manners.

Leave a Reply