💻 ALL ABOUT GIT (version control tool)

💻 ALL ABOUT GIT (version control tool)


Git is a distributed version-control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed non-linear workflows.

What is the purpose of Git?

Git is primarily used to manage your project, comprising a set of code/text files that may change.

But before we go further, let us take a step back to learn all about Version Control Systems (VCS) and how Git came into existence.

Version Control is the management of changes to documents, computer programs, large websites and other collections of information.

There are two types of VCS:

  • Centralized Version Control System (CVCS)

  • Distributed Version Control System (DVCS)

Centralized VCS

A centralized version control system (CVCS) uses a central server to store all files and enables team collaboration. It works on a single repository to which users can directly access a central server.

Please refer to the diagram below to get a better idea of CVCS:

Centralized Version Control System Workflow - What Is Git - Edureka

The repository in the above diagram indicates a central server that could be local or remote which is directly connected to each of the programmer’s workstations.

Every programmer can extract or update their workstations with the data present in the repository or can make changes to the data or commit in the repository. Every operation is performed directly on the repository.

Even though it seems pretty convenient to maintain a single repository, it has some major drawbacks. Some of them are:

  • It is not locally available; meaning you always need to be connected to a network to perform any action.

  • Since everything is centralized, in any case of the central server getting crashed or corrupted will result in losing the entire data of the project.

This is when Distributed VCS comes to the rescue.

Distributed VCS

These systems do not necessarily rely on a central server to store all the versions of a project file.

In Distributed VCS, every contributor has a local copy or “clone” of the main repository i.e. everyone maintains a local repository of their own which contains all the files and metadata present in the main repository.

You will understand it better by referring to the diagram below:

Distributed Version Control System Workflow - What Is Git - Edureka

As you can see in the above diagram, every programmer maintains a local repository on its own, which is actually the copy or clone of the central repository on their hard drive. They can commit and update their local repository without any interference.

The three layers are:

  • Working directory: This is created when a Git project is initialized onto your local machine and allows you to edit the source code copied.

  • Staging area: Post the edits, the code is staged in the staging area by applying the command, git add. This displays a preview for the next stage. In case further modifications are made in the working directory, the snapshots for these two layers will be different. However, these can be synced by using the same ‘git add’ command.

  • Local repository: If no further edits are required to be done, then you can go ahead and apply the git commit command. This replicates the latest snapshots in all three stages, making them in sync with each other.

Install git: -

You should be running a server with any Ubuntu 16.04 LTS release. You will need to log in to SSH via the root user.
apt-get update

\>> apt-get install git-core

\>> git --version

Installing GIT - apt-get install

Local Git bucket :-

\>> mkdir myproject – Create a directory

\>> cd myproject – navigate to the directory

\>> git init – initialize the git

\>> touch nerdycloudfile – create a file in my project

\>> git status

\>> git add nerdycloudfile
git commit –m ‘commit message’

\>> git log

\>> gibucket – sign In – root/root (username & password) >> Goto system Adminstration – New user – Create user with credentials – sign out - sign in with newly created user >> New repository - Create a repository >> git remote add origin URL

\>> git push –u origin master

\>> View the file called “.gitbucket” (hidden folder)

\>> Give the command “- tree .gitbucket “ to view the files in the repository



whenever we do our first commit our default branch will be automatically created.

Git Branches:-

Branching, in version control and software configuration management, is the duplication of an object under version control (such as a source code file or a directory tree) so that modifications can occur in parallel along multiple branches.

Branches are also known as trees, streams or codelines. The originating branch is sometimes called the parent branch, the upstream branch (or simply upstream, especially if the branches are maintained by different organizations or individuals), or the backing stream. Child branches are branches that have a parent; a branch without a parent is referred to as the trunk or the mainline.

\>> git branch

\>> git branch newbranchname

\>> git checkout branch to change

\>> git merge branchnametomerge

\>> git checkout master

\>> git branch f1 && git branch f2 (to create two branches at a same time)

\>> git branch –D branchname (to delete branch)

\>> git push origin --delete branchname

\>> git push origin --all

Stash Area:-

\>> git add.

\>> git stash save filename

\>> git stash list – To view the stashed files

Play with data in Stash Area

\>> Copy + paste = Take a copy from the stash area and use it in normal git stash apply stashed

\>> Cut + paste = Move a file from stash and use it normally git stash pop stashID

\>> Delete = Remove files from stash

Area >> git stash drop stashID


Creating Version tags:-

\>> git tag version number = Creating a version tag

\>> git tag = Wrapping the files and pushing into version

\>> git push –u myproject version number = Pushing into github

\>> git tag –d version number = Remove versions locally git push –u myproject --delete version number = Delete the release

in the git hub

Configuring GIT:

Git config --global --edit


\>>git revert <commit it>

COMMIT ID can be obtained from the output of >>git log

\>>git diff <commit id 1><commit id 2>

Email Notification:

\>> Whatever happens in GitHub will be notified through email

\>> Steps to activate email notification

\>> Login into Git Hub - myproject – Settings – Notifications – Add - Email Address.


\>>git mergetool --tool=vimdiff

Backup and Restore:

\>> For taking the backup of the files of the git bucket.it is a hidden folder.

\>> ls –a (View hidden files)

\>> open the .gitbucket (we can see the files which were pushed.


DO FOLLOW Kanishthika Singh

  • 👀 I’m interested in learning and working with the community, open source contributions and giving back to the community.

  • ⛷️ I'm currently working with Kubernetes, Docker, Ansible, AWS, Jenkins, Terraform, CI/CD, Git & GitHub

  • 💞️ I’m looking to collaborate on GitHub and open-source projects related to cloud computing and DevOps.

  • 📝 I regularly write articles on interesting topics.

  • 💬 Ask me about DevOps, Linux,Jenkins, CI/CD, Bash, Shell Kubernetes, Docker, Ansible,
    📫 Reach out to me at Kanishthikasingh2001@gmail.com