Git is free and open source Distributed Version Control System (DVCS). Git was created by Linux Torvalds in 2005 for the development of Linux Kernel, with other kernel developers contributing to its initial development. Its current maintainer since 2005 is Junio Hamano.

Git is responsible for keeping track of changes to content usually source code files. It is designed to handle everything from small to very large projects with speed and efficiency. It provides mechanisms for sharing that content with others. It helps software developers to work simultaneously and maintaining history of every version. 

This post will help to on board Git from basics to professional level.

Centralized Version Control System vs Distributed Version Control System

Centralized Version Control System uses a central server to store all files and enables team collaborations. It works on a single repository to which users can directly access a  central server.

Repository Management

At Git, We manage our projects at repository. Git provides wide flexibility to manage our code. The following diagram represents the user repository strategy one of the most adopted method for managing repository.
Git User Strategy
At 'Git User Strategy' we will have a master remote repository which should have master branch, release branch and develop branch where master branch should contain live code, release branch should contain  QA code and develop code will contain all the valid code merged from user remote repository.

Each user should fork from the master repository and create copy as user remote repository, Then they will clone from the user remote repository to their local machine and start working.

Create Organization & Repository

  1. We need to create the master remote repository under organization at any of the Git platforms such as GitHub, BitBucket, GitLab, etc. All the below examples are bases on GitHub, so do sign up at GitHub and have a GitHub user account account ready.
  2. Create organization from https://github.com/organizations/new where give some unique name for the organization from the created GitHub user account. Here "harishshanblogspot" is the organization name.
    Creating Organization
    Inviting organization members
  3. Create master remote repository from the created organization. Here "example" is the master remote repository name.

  4. Then all the users work on the project should fork from the master remote repository to create their user forked remote repository.
Once we have created the master remote repository and created forked user remote repository at GitHub. We can start working on our project from our local machine, The following example shows how to install Git, configure Git user account and start working on git commands from Windows.

Install Git at Windows

  1. Download Git from https://git-scm.com/download/win
  2. Run the downloaded Git setup for installing Git
  3. While installing make sure the following configurations
    To use Git commands from windows command prompt
    To use OpenSSL Library for validating certificates
    **Always use "Checkout windows-style, commit Unix-style line ending" to avoid CRLF issues while team is using different Operating-systems.

Concepts Of Git:

Repositories, Branches, Remotes, Committing, Pushing, Pulling, Merging, Rebasing, Reverting and Cherry-Picking

Concepts of GitHub:
Pull-Requests, Issues, Wiki, Forking, Remote Repositories, Gist

Simple Git Commands

git config

We need to configure the GitHub user account with user name and email address of created GitHub account. The following is the syntax for configuring user name and email, Where we need to replace the username and email-address with the created GitHub account.
git config --global user.name <username>
git config --global user.email <email-address>

git clone

Clone the created the project, the following is the example of 'git clone' command used to clone the repository at our local machine. This command can be executed at local machine git workspace directory where we want to clone the repository. Where git@github.com:harishshan/example.git is the user remote repository
git clone git@github.com:harishshan/example.git 

git status

The 'git status' command will display the status and recommend us the next step.

git status

git add & git commit

The 'git add' command is used to add un-tracked modification/new file to staging from working area. This one helps us to segregate which changes are effective, we can ignore the rest of the changes are working area.
The syntax of 'git add' command for adding files by relative file path
git add <file1> <file2>
The following command can be used when we want to add all the changes from working directory to staging
git add .
The 'git commit' command is used to record our changes to the local repository. All the files added at staging area will be moved when we do 'git commit'. For each commit, git will return a unique commit id of length 40. Where -m parameter is mandatory used to mention the commit message
git commit -m "Commit Message"

git push

The 'git push' command is used to push the committed changes from the local machine repository to upstream. By default it will be pushed to origin remote repository and current branch.
git push

git pull

The 'git pull' command is used to pull the committed changes from the upstream to local machine repository. By default it will be pulled from the  origin remote repository and current branch.
git pull

git remote

The 'git remote' command used to manage the remote repositories. The following command is used to list the remote repositories added for the current local repositories.
git remote -v
The following command is used to add the upstream remote repositories. We already cloned from the user remote repository and now we adding Master remote repository. Where git@github.com:harishshanblogspot/example.git is the Master remote repository. We can verify the added remote repositories using the 'git remote -v'.
git remote add parent git@github.com:harishshanblogspot/example.git

Git Use-cases

<<<<<<<<<<<<<<<Still Editing>>>>>>>>>>>>>>>