Git Tutorial – Basic Concept and Commands

Git Tutorial – Basic Concept and Commands

In “Git Tutorial”, we will be learning what is git?, what are advantages and disadvantages of git?, Useful Git commands?

Git is a DevOps tool used for source code management. It is one of the most prominent version control systems (VCS) today that is widely used to handle small and large projects efficiently. It helps in tracking changes in source code, enabling different people to collaborate on different parts of the same program.

Git is a version control system for tracking changes in computer files. It helps in coordinating work amongst several people in a project and tracks progress over time. Unlike the centralized version control system, Git branches can be easily merged. A new branch is created every time a developer wants to start working on something. This ensures that the master branch always has a production-quality code.

Git is a distributed version control system, so here, every developer gets their local repository with full commit history. The commit history makes Git fast, as now a network connection is not needed to create commits or perform diffs between commits.

 

Git is an open source distributed version control system created in 2005 by Linus Torvalds and others from the Linux development community. Git can work with many types of projects, but it’s most commonly used for software source code.

Git is foundation of many services like GitHub and GitLab, but we can use Git without using any other Git services. Git can be used privately and publicly.

Git is easy to learn, and has fast performance. It is superior to other SCM tools like Subversion, CVS, Perforce, and ClearCase.

 

Advantages of Git

  1. Free and open source:

Git is released under GPL’s open source license. It is available freely over the internet. You can use Git to manage property projects without paying a single penny. As it is an open source, you can download its source code and also perform changes according to your requirements.

 

  1. Fast and small:

As most of the operations are performed locally, it gives a huge benefit in terms of speed. Git does not rely on the central server; that is why, there is no need to interact with the remote server for every operation. The core part of Git is written in C, which avoids runtime overheads associated with other high-level languages. Though Git mirrors entire repository, the size of the data on the client side is small. This illustrates the efficiency of Git at compressing and storing data on the client side.

 

  1. Implicit backup:

The chances of losing data are very rare when there are multiple copies of it. Data present on any client side mirrors the repository, hence it can be used in the event of a crash or disk corruption.

 

  1. Security:

Git uses a common cryptographic hash function called secure hash function (SHA1), to name and identify objects within its database. Every file and commit is check-summed and retrieved by its checksum at the time of checkout. It implies that, it is impossible to change file, date, and commit message and any other data from the Git database without knowing Git.

 

  1. No need of powerful hardware:

In case of CVCS, the central server needs to be powerful enough to serve requests of the entire team. For smaller teams, it is not an issue, but as the team size grows, the hardware limitations of the server can be a performance bottleneck. In case of DVCS, developers don’t interact with the server unless they need to push or pull changes. All the heavy lifting happens on the client side, so the server hardware can be very simple indeed.

 

  1. Easier branching:

CVCS uses cheap copy mechanism, If we create a new branch, it will copy all the codes to the new branch, so it is time-consuming and not efficient. Also, deletion and merging of branches in CVCS is complicated and time-consuming. But branch management with Git is very simple. It takes only a few seconds to create, delete, and merge branches.

Benefits of Git:

Some significant benefits of using Git are as follows:

  1. Saves Time:

Git is lightning fast technology. Each command takes only a few seconds to execute so we can save a lot of time as compared to login to a GitHub account and find out its features.

  1. Offline Working:

One of the most important benefits of Git is that it supports offline working. If we are facing internet connectivity issues, it will not affect our work. In Git, we can do almost everything locally. Comparatively, other CVS like SVN is limited and prefer the connection with the central repository.

  1. Undo Mistakes:

One additional benefit of Git is we can Undo mistakes. Sometimes the undo can be a savior option for us. Git provides the undo option for almost everything.

  1. Track the Changes:

Git facilitates with some exciting features such as Diff, Log, and Status, which allows us to track changes so we can check the status, compare our files or branches.

 

General workflow is as follows −

  1. You clone the Git repository as a working copy.
  1. You modify the working copy by adding/editing files.
  1. If necessary, you also update the working copy by taking other developer’s changes.
  1. You review the changes before commit.
  1. You commit changes. If everything is fine, then you push the changes to the repository.
  1. After committing, if you realize something is wrong, then you correct the last commit and push the changes to the repository.

Different Commands in Git

There are many different git commands for different purposes:

  1. Git init Command
  2. Git add Command
  3. Git Commit Command
  4. Git Clone Command
  5. Git Config Command
  6. Git Alias Command
  7. Git Checkout Command
  8. Git Pull Command
  9. Git Push Command
  10. Git Fetch Command
  11. Git Status Command
  12. Git Revert Command
  13. Git Remove (rm) Command
  14. Git LOG Command
  15. What is Git – Why Git Came into Existence?Git Config Command
  16. Git Cheat Sheet