top
upGrad KnowledgeHut SkillFest Sale!

Search

GIT Tutorial

1. Version Control System(VCS): Merits, Types and Distributed VCSA Version Control System helps you save your data in a more readable and logical way, and in-case you mess up you could restore a good version of your data.Not just that; you could also concurrently share your data with the peers.Benefits of Version Control:A best version control software is expected to have the below features:Backup and restore: Data is always secure, saved and available for restore.Understanding what happened: History, commit messages and different tools helps you understand what changed in each version and how your project evolved.Synchronization and Collaboration: Synchronize and collaborate work with others & yet work independently(branching) without corrupting each other’s data.Storing versions and track ownership: store versions in a more readable, rememberable way while tracking every bit of change. (blame/praise the changes)Some of the popular version control system list:BitKeeper, ClearCase, SVN-SubVersion, Mercurial, CVS-Concurrent Version Control System, GitTypes of VCS: Centralized and De-centralizedCentralized Version Control System (CVCS): Each developer’s change must go into the main trunk before it can be seen by othersExamples: CVS, SVN, ClearCaseDe-centralized or Distributed Version Control System (DVCS):In a DVCS every developer has its own repo and can choose when he wish to publish/share his changes.Examples: BitKeeper, Mercurial, GitAdvantages of DVCS:Different topologies:Centralized: Developers push changes to one central repository.Hierarchical: Developers push changes to subsystem-based repositories.                     Sub-system repos are periodically merged into a main repository.Distributed: Developers push changes to their own repository.                   Project maintainers pull changes into the official repositoryBackups are easy: Each clone is a full backup, most operations are offline, hence faster.Reliable branching/merging: easy and quick, allows feature and hotfix/bugfix branches.Ease restore: local work also committed and under version control; allows stable rollback changesEasy collaboration: peers can communicate and collaborate with each other.2. What is Git and its merits – why use git?Git quick historyLargest “Linux Kernel development” project largely relied on “BitKeeper” VCS for its code.“BitKeeper” withdrew its free use of the softwareLinus Torvalds Officially released the VCS “Git” in 2005Goals to develop Git:SpeedSimple design with multiple workflowsStrong support for non-linear development (thousands of parallel branches)Strong and easy merging of branchesFully distributedAble to handle large projects like the Linux kernel efficientlySome high-Profile companies that switched to Git:Linux, Google, Facebook, Microsoft, Twitter, LinkedIn, Netflix, Android, Amazon, Cisco, IBM, Intuit, Accenture, Apple IOS.Git merits:Snapshots, not differences: Git stores data as snapshots of mini filesystem over a period of time.Fast: Most of the operations are localGit only adds data: Every operation adds data and after a commit, it’s very difficult to lose data.Undo mistakes easilyComplete and descriptive revision historyOpen source LibrariesEasy and powerful Branching and mergingGit has integrity-data assurance:Everything in Git is check-summed before it is stored. SHA-1 hash, hexadecimal addresses. If you have a commit id, you could be assured not only that your project is exactly the same as when it was committed, but that nothing in that history was changed.Easy backup and recovery from a clone on another machine3. Git architecture and terminologiesDiagram: The 3-tier architectureNote: “Staging area” is further divided into “Staged” and “Un-staged” layers.RepositoryA hub to store all the project data/files and store each file’s revision history. Repositories can have multiple collaborators and may be either public or private.Working directoryYour local copy of the repository wherein you can modify the code and choose to publish it.CommitSaving a snapshot of the entire work directory with a unique id and a message and other details like who changed what file and when.Index (Staging area|Cache|Tracking area)snapshot of your next commit .git hashGit computes the SHA-1 hash of a file with a hash value of 160 bits that uniquely identifies the contents of the file. Two files with identical contents will have the same hash value. Two files with different contents will have different hash values.CloneA clone is a copy of a repository that lives on your computer instead of on a website's serverBranchA parallel or independent line of development. (In other words: A refname for the recent commit)MasterYour local default branch, master pointer points to the latest commit you make.HEAD = snapshot of your last/latest commit.The HEAD is a pointer to the most recent commit on the current branch. It is a hash value of the commit.In other words: HEAD is a short name/reference to a SHA-1 of a commit id.HEAD moves forward with each commit.RemoteThis is the version of something that is hosted on a server, most likely GitHub.com. It can be connected to local clones so that changes can be synced.4. Install GitOfficial git download link: https://git-scm.com/downloadsRefer the link for documentation: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git--To check the git installed location:$which git $/usr/local/bin/git--View the installed git version:$git --version $git version 2.19.0How to use git:Git can be used as a CLI (Command line tool) or as a GUI tool or as a git plugin.This git version control tutorial focuses on using git as a CLI to get the best out of git commands.
logo

GIT Tutorial

Introduction to Git

1. Version Control System(VCS): Merits, Types and Distributed VCS

A Version Control System helps you save your data in a more readable and logical way, and in-case you mess up you could restore a good version of your data.

Not just that; you could also concurrently share your data with the peers.

Benefits of Version Control:

A best version control software is expected to have the below features:

  • Backup and restore: Data is always secure, saved and available for restore.
  • Understanding what happened: History, commit messages and different tools helps you understand what changed in each version and how your project evolved.
  • Synchronization and Collaboration: Synchronize and collaborate work with others & yet work independently(branching) without corrupting each other’s data.
  • Storing versions and track ownership: store versions in a more readable, rememberable way while tracking every bit of change. (blame/praise the changes)

Some of the popular version control system list:

BitKeeper, ClearCase, SVN-SubVersion, Mercurial, CVS-Concurrent Version Control System, Git

Types of VCS: Centralized and De-centralized

Centralized Version Control System (CVCS): 

Each developer’s change must go into the main trunk before it can be seen by others

Examples: CVS, SVN, ClearCase

De-centralized or Distributed Version Control System (DVCS):

In a DVCS every developer has its own repo and can choose when he wish to publish/share his changes.

Examples: BitKeeper, Mercurial, Git

Types of VCS: Centralized and De-centralized

Advantages of DVCS:

  • Different topologies:
    • Centralized: Developers push changes to one central repository.
    • Hierarchical: Developers push changes to subsystem-based repositories.
                           Sub-system repos are periodically merged into a main repository.
    • Distributed: Developers push changes to their own repository.
                         Project maintainers pull changes into the official repository
  • Backups are easyEach clone is a full backup, most operations are offline, hence faster.
  • Reliable branching/merging: easy and quick, allows feature and hotfix/bugfix branches.
  • Ease restore: local work also committed and under version control; allows stable rollback changes
  • Easy collaboration: peers can communicate and collaborate with each other.

2. What is Git and its merits – why use git?

Git quick history

  • Largest “Linux Kernel development” project largely relied on “BitKeeper” VCS for its code.
  • “BitKeeper” withdrew its free use of the software
  • Linus Torvalds Officially released the VCS “Git” in 2005
  • Goals to develop Git:
    • Speed
    • Simple design with multiple workflows
    • Strong support for non-linear development (thousands of parallel branches)
    • Strong and easy merging of branches
    • Fully distributed
    • Able to handle large projects like the Linux kernel efficiently

Some high-Profile companies that switched to Git:

Linux, Google, Facebook, Microsoft, Twitter, LinkedIn, Netflix, Android, Amazon, Cisco, IBM, Intuit, Accenture, Apple IOS.

Git merits:

  • Snapshots, not differences: Git stores data as snapshots of mini filesystem over a period of time.
  • Fast: Most of the operations are local
  • Git only adds data: Every operation adds data and after a commit, it’s very difficult to lose data.
  • Undo mistakes easily
  • Complete and descriptive revision history
  • Open source Libraries
  • Easy and powerful Branching and merging

Git merits

  • Git has integrity-data assurance:

Everything in Git is check-summed before it is stored. SHA-1 hash, hexadecimal addresses. If you have a commit id, you could be assured not only that your project is exactly the same as when it was committed, but that nothing in that history was changed.

  • Easy backup and recovery from a clone on another machine

3. Git architecture and terminologies

Git architecture and terminologiesDiagram: The 3-tier architecture

Note: “Staging area” is further divided into “Staged” and “Un-staged” layers.

Repository

A hub to store all the project data/files and store each file’s revision history. Repositories can have multiple collaborators and may be either public or private.

Working directory

Your local copy of the repository wherein you can modify the code and choose to publish it.

Commit

Saving a snapshot of the entire work directory with a unique id and a message and other details like who changed what file and when.

Index (Staging area|Cache|Tracking area)

snapshot of your next commit .

git hash

Git computes the SHA-1 hash of a file with a hash value of 160 bits that uniquely identifies the contents of the file. Two files with identical contents will have the same hash value. Two files with different contents will have different hash values.

Clone

A clone is a copy of a repository that lives on your computer instead of on a website's server

Branch

A parallel or independent line of development. (In other words: A refname for the recent commit)

Master

Your local default branch, master pointer points to the latest commit you make.

HEAD = snapshot of your last/latest commit.

The HEAD is a pointer to the most recent commit on the current branch. It is a hash value of the commit.

In other words: HEAD is a short name/reference to a SHA-1 of a commit id.

HEAD moves forward with each commit.

Remote

This is the version of something that is hosted on a server, most likely GitHub.com. It can be connected to local clones so that changes can be synced.

4. Install Git

Official git download link: https://git-scm.com/downloads

Refer the link for documentation: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git

--To check the git installed location:

$which git
$/usr/local/bin/git

--View the installed git version:

$git --version
$git version 2.19.0

How to use git:

Git can be used as a CLI (Command line tool) or as a GUI tool or as a git plugin.

This git version control tutorial focuses on using git as a CLI to get the best out of git commands.

Leave a Reply

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

Comments

Ezeelogin

Thanks for the post. I liked the way all the details have been provided!

stephen

Firstly thanks for providing this tutorial from this article I have gathered lots of information. I can say that whatever the information provided by knowledgeHut is more useful to know more about the git.

Saurabh

Written nicely