What Is Git Software?

Git was developed by Linux creator Linus Torvalds for managing the Linux kernel source code. When I started working with git, I directly started implementing the Git commands without understanding the meaning behind them. So, it had been an arduous task for me to use git. Since then, I have been studying git in a more comprehensive way. So, this article aims to provide an overview of git along with explaining the basics of it.

INTRODUCTION TO GIT :


Git is open source software for maintaining version controls and non-linear workflow effectively. It is used by programmers to manage the source code and maintain it collaboratively. It snapshots the directory trees of the file so data integrity is well maintained. It is very useful in handling small as well as large projects as it has a locally stored repository. Hence it fetches data from that local repository rather than fetching it from a remote server, making it faster than many other version control systems (VCS).

Git provides security by using the SHA (Secure Hash algorithm). It can be used in any operating environment as well as integrated systems. Hence, it provides flexibility as well. One of the most important features of git is that it is distributed. Hence, one need not export the project source code from one system to another. Git stores the source code in the local repository. Hence it can be accessed by multiple users at the same time and then the final changes can be pushed to the remote repository.

ARCHITECTURE OF GIT :

The working of git is surprisingly simple if understood correctly. In git, the commits made are saved as snapshots. Unlike others, git uses three-tier architecture. The workflow of git is as follows:

Figure 1 Git Repository Workflow

It consists of a local repository, remote repository, and staging index. The changes are made in the local repository. Then these changes are passed to the staging index. Then it is committed to the remote repository. This architecture makes it easy to handle multiple changes at the same time. 

BASIC TERMINOLOGIES OF GIT:

  • BRANCH: - A pointer to a specific commit is referred to as a branch in git. You can create, delete, rename and list the various branches.
  • CHECKOUT: - It lets you traverse between various branches. Checking out a branch updates the changes in the working directory.
  • CLONE: - It is used to create a copy of the existing directory.
  • FETCH: - It is used to access and download the contents from the remote repository.
  • HEAD: - The current or active branch is referred to as the head. It is stored in the git repository, in .git/HEAD.
  • INDEX: - The staging area between the working directory and remote directory is known as the index. 
  • MASTER: - When the file is downloaded from the remote server to the local repository then it has a local branch named master. It is the repository’s default branch.
  • MERGE: - It is used to convert various commits into one unified history. It is used to preserve forked history.
  • PUSH: - It is used to upload the contents of the local repository to the remote repository.
  • PULL: - It is used to access the data from the remote repository and directly update the content of the local repos

Figure 2 Terminology Workflow

BASIC COMMANDS IN GIT :

GIT INIT: - It is used to create a new blank repository. It converts the existing project into the git project.
 
$git init                                                                                                    

GIT STATUS: - The state of the working directory and the staging area can be displayed using the status command.

$git status                                                                                                 

GIT ADD: - The add command is used to add one or multiple files to the staging area.

$git add <File name>                                                                               

GIT COMMIT: - It is used to save the changes and generate a commit id for every change made.

$git commit                                                                                               

GIT CLONE: - It is used to generate the copy of the remote repository using the remote URL.

$git clone <repository URL>                                                                     

GIT STASH: - It is used to navigate through various branches without committing the changes made in the working directory.

$git stash                                                                                                     

GIT SHOW HEAD: - It is used to check the location of the current working directory.

$git show HEAD                                                                                        

GIT DIFF: - It is used to locate the changes that are not being staged yet.

$git diff                                                                                                       

GIT LOG: - It is used to display the status of the head and the most recent commits.

$git log                                                                                                        

 GIT BRANCH: - It is used to display all the branches.

$git branch                                                                                                   

 GIT CHECKOUT: - It is used to navigate through the branches.

$git checkout <branchname>                                                                      

 GIT FETCH: - It is used to fetch the complete repository using the repository URL.

$git fetch <repository URL>                                                                       

 GIT PULL: - It is used to access the data from a remote server to the working directory.

$git pull <option> [<repository URL> <refspec>…]                                  

 GIT PUSH: - It is used to push the data from the local repository to the remote repository.

$git push <option>[<Remote URL> <branch name>  <refspec>...]            

 GIT REBASE: - It is used to rebase any commits made in the master branch or test branch.

$git rebase <branch name>                                                                           

 GIT CHERRY-PICK: - If by mistake changes made are committed in the wrong branch then cherry-pick helps to commit changes from one branch to another branch.

$git cherry-pick <commit id>                                                                        

CONCLUSION: -


To sum up, the amount of flexibility makes git the best choice for programmers all over the world. With this, I end this article hoping that all the basics required are mentioned here. My next blog is going to be about services provided by git like GitHub and Gitlab. 
Do you know what GitHub & GitLab is and what’s the difference between them?

REFERENCES: -


Comments