What is Git and Github ? And why is it so important?

What is Git and Github ? And why is it so important?

ยท

5 min read

Hey there, in this blog we are going to learn about Git and Github. As a developer, you might have come across the terms Git and Github but do you understand why you need these or why you are using these? Let's dig a little deeper in this topic.

image.png

Git and Github are the most important tools for a software developer.

Before diving into the specifics of these two, let us understand the basic workflow of a software development company. Then you will understand properly why these tools will be useful in your development journey.

Let say a company "A", have several different projects. Probably 5-6 persons probably might be working on a particular project. So each and every person will be handling different parts of the project. Say the project is to build a Pharma Website. So one person will be working on the HTML part, other person will be working on the styling and design, and the third person is working on Javascript and the remaining are working on the back-end, that is the server side which includes database and servers.

After finishing each feature of the project, each of them will upload their code to a common folder in the cloud. Before the code is saved to the folder, the code will be reviewed by the other members in the firm, so that there are no errors in the code. If everything is OK, then the code is moved to the common folder. Or the reviewer may suggest changes, and after the changes are done, and if the reviewers approve, then it can be moved to the main folder.

This is the basic workflow that happens in a company. Now to be very specific, the common folder in the cloud is called a repository or repo for short. The cloud in which repository is present or say hosted is the so-called Github. Hope you guys are getting it.


Now what is Git?

Git is basically a version control tool that helps a developer to track what all changes he/she has done in the code. Take the example of a simple calculator program in Java(my favourite language) . The user inputs the first and second number and then user selects an option, say there is only addition and subtraction. According to his/her selection, program will return the result. If he chose addition, sum of two numbers will return. If he chose subtraction, the difference will return. Now he saved the program.

image.png

Now assume, he needs a new functionality of multiplication. So he writes the method of multiplying two numbers and return the product, and he saves it again. Now his boss says that the client doesn't need multiplication functionality. So what does he do now ?

He needs to get back and remove the code of multiplication right ? Since this is a very small program it is easier to do. But in companies, sometimes a task assigned to a person will require making changes to several files. And after making all the changes, suppose the boss says that the new change is not necessary. What will you do ? Will go back and rewrite the code ?

This is where Git comes to the picture. If we had used git for saving, then each time we save, it is going to be saved as a different checkpoint. Assume this checkpoint as the savepoint in games. Whenever we die in game, we start from the savepoint. Same goes with the Git, whenever we save a file or function in Git, we create a new checkpoint. And we can comeback to any checkpoint we want.

In Git each of these checkpoints are termed as hashes. Each hash is 40 character long hex digit. Since it uses SHA-1 algorithm to create hash.


What is Github ?

image.png

Github is the cloud-based hosting service for Git repositories. It is a tool built on the top of Git. In simple terms, it provides graphical interface that interact with Git repositories. It makes it easier for individual and team to use Git for version control and collaboration features such as bug tracking and feature request for every project.

You can use Github through a web portal or desktop GUI or Git Shell.


Here is the list of some commonly used Git commands

  • Initialize : initializes a git repository in your current folder.
    $ git init

  • Clone : used to create a copy of existing Git repository.
    $ git clone <repository name>

  • Add : add changed files to the staging area, which can be saved in the repository after committing.
    $ git add <file-name> for adding a specific file
    $ git add . for adding all the files

  • Status : shows the status of the working tree
    $ git status

  • Commit : save your changes to the local repository
    $ git commit -m "commit message eg- initial commit"

  • Push : uploads all the saved to specific remote branch
    $ git push origin <remote-branch-name>

  • Pull : to download and integrate remote branches in the local branch
    $ git pull origin <remote-branch-name>

  • Branch : to create a new branch in the tree
    $ git branch <new-branch-name>

  • Checkout : used for changing the branch
    $ git checkout <branch-name>

  • Merge : used to merge 1 branch with the other branch
    $ git merge <branch-name>

  • Delete : remove the branch from the tree
    $ git branch origin --delete <branch-name>

You can checkout the official documentation of the Git here.

And at the very last, this is my personal Github profile.

I hope this article is useful to you. Thanks for reading, and keep learning! ๐Ÿค

ย