Getting Started With Git

Introduction

In the field of Software Development, every developer must create a backup of the task because it would be necessary for every developer. In other words, a system with which we can recall our specific version later.

In the same context, there is a system available named Git. Git is a free and open source distributed version control system that handles the projects, whether the project is large or small, very efficiently. Git is very easy to understand and performance is very fast and smooth.

Git has the following few goals:

  • Speed
  • Simple Design
  • Strong support for the non-linear development
  • Fully Distributed
  • Handle Large Projects

Overview

There are various Version Control Systems in Git that are the very important and most usable systems.

Version Control System

Whenever any changes are made to a file or a set of files, a Version Control System records the changes. We can also recall the specific versions whenever we need it.

As I stated earlier, if the developer wants to maintain a task with multiple versions then the Version Control System (VCS) is great to use because the VCS grants the developer the ability to restore a file to a previous state, change the project back to its previous state, analyze the changes and we can also see who modified it last and more. There is the advantage that we can recover the files easily.

Local Version Control Systems

Usually, people just copy the files from one directory to another directory. This is the very simple and common approach, but errors can also occure from that. It can also happen that you copy the file to the wrong directory because in the large projects it may be possible that you can forget the directory.

To overcome this issue the Local Version Control System is developed that had the simple database that maintains all the changes in files under a revision control system.

Local Version Control System

There is a popular tool of VCS, RCS. This system is still distributed with many computers. The Mac OS X operating system includes the rcs command when the developer tool is installed.

Customized Version Control Systems

The next issue with developers is that they need to cooperate with developers on other systems. To overcome that problem, the CVCS was developed. It hs the single server and all versioned files are saved into it and all clients can check out the files from that central place. This has been the standard system for VCS for many years.

Centralized Version Control

This system has the advantage that everyone can check on a project to determine what is going on in the project. The Administrator has the rights for everyone so that admin has control of who can do what.

This system also has disadvantages. Suppose the server goes down, in this condition no one can do anything related to the project. If the hard disk crashes then the database becomes corrupted and if the backup hasn't been taken or is not available then it may be possible that developers have lost the entire history of the project. The same problem with the local VCS is, when you have the project on a single machine, you risk losing everything.

Distributed Version Control Systems

Now, the distributed VCS enters. Now the clients not only check out the snapshots of the files but also they can have the full mirror of the repository. Now if there is any problem with the server, clients can backup the data using other systems. With the help of this the remote repositories are also possible and you can hook up with the various groups within the same project; that is not possible with the CVCS and VCS.

Distributed Version Control

  Installing Git

You can easily download it from here.

Git Commands 

There are various commands used in Git. Some of them are defined below:

git init

It creates an empty repository and also reinitialize an existing one. It creates an empty directory named .git. An initial HEAD file that references the HEAD of the master branch is also created.

Example

git init Sample

It initializes an empty git repository.

Output

Init on git

git add

To add a new file, create a file from Notepad and save it to that Sample directory. Now we need to add this file from the git add command. At first you must be in the Sample repo.

Example

cd ~/Sample/

git add Readme.txt

git commit -m "One file added"

Output

Add and Commit on Git

git config

It sets the configuration values for the user name, user email and file formats and more.

Example

Creating User Name- git config --global user.name Nimit Joshi

Creating User Email- git config --global user.email [email protected]

It creates the user name and user email.

Output

Create User Name and Email on Git

We can also check out the created user name and email.

Watching UserName and UserEmail on Git

git status

It shows the status of files in the working directory. It'll also list out the untracked, updated files.

git pull

It gets the file from the remote repository and integrates it with the local file.

Example

git pull origin

git push

It sets all the changes to the local files to the remote repository.

Example: git push origin master

git rm

It removes the files from the directory.

Example: git rm filename

Output

Removing File on Git

Summary

This article describes the git and various version control systems. You can also check out the git commands in here. Thanks for reading.

Up Next
    Ebook Download
    View all
    Learn
    View all