HomeBlogSoftware DevelopmentGit Tutorial For Beginners: Learn Git from Scratch

Git Tutorial For Beginners: Learn Git from Scratch

Read it in 8 Mins

Last updated:
17th Mar, 2022
Views
1,500
In this article
View All
Git Tutorial For Beginners: Learn Git from Scratch

Protecting the source code is a crucial part of the software development process, especially when complex code is involved since developers must understand the issues or bugs that have been fixed. Therefore, many software developers use a version control system to ensure that the source code remains intact. It is nothing but a set of software tools that allow developers to track and review the changes made in the software codes. One such version control tool is the GIT. 

Check out our free courses to get an edge over the competition 

Let’s delve deep into GIT in this detailed blog. 

Learn Software Development Courses online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs or Masters Programs to fast-track your career.

Ads of upGrad blog

What is GIT?

Before you understand what GIT is, it is essential to know the different types of version control systems. It is mainly of three kinds – local, centralised, and distributed. Developers commonly use the distributed version control system for projects that require large bandwidth. It facilitates tracking the changes made to the code when multiple developers work on the same code.

GIT is a distributed version control system that efficiently tracks and stores changes in large-scale projects that involve several versions of a single code. One of the significant advantages of using GIT over other distributed version control systems is its speed. Developers can immediately retrieve a modified version of the code because of the parallel branching mechanism in GIT.

Check out upGrad’s Java Bootcamp

Basic Functioning of GIT

The storing procedure in GIT consists of three steps, namely, committing, modification, and staging. However, before you understand the different states of GIT, you should be familiar with the concept of repositories. They serve as the core element of version control systems. It is similar to a data folder or data structure that stores various modified files. Repositories are available both on a local network through the Internet and on a remote server. 

First, you need to add files to the repository for storage on the local database. This is known as committing the files on GIT. The next state of modification is when changes are made to a file but not stored on a repository. It is called staffing which involves marking the modified file to move it to the local repository. Finally, when the files are committed in the local repository, they move to the remote repository. 

Check out upGrad’s Full Stack Development Bootcamp (JS/MERN) 

To record the changes in the remote repository, you need to take the following steps:

  • To begin with, you need to add the modified files to the local index or database. Then commit the files to the local repository.
  • Then, you need to use a different viewer tool to track the changes made in the file stored in the repository and new changes.

The entire process is carried out through the different sections in GIT – the Git directory, the working directory, and the staging area. One of the most important sections is the GIT directory, where a file’s metadata is saved. When you copy a file from a remote repository, the compressed metadata helps identify the file and understand the changes.

The working directory acts as a checkout step from the GIT directory. It decompresses the files stored in the initial database and transfers them to a disk to allow programmers to use or modify the file.

Last is the staging area that works as an index. It decides which file shall go next for commit. Therefore, the GIT process involves modifying files, staging them, and committing them to the repository.

GIT Terminologies

  • Blobs:- In GIT, the binary large objects are caller blobs. They represent the file version. Even though blobs comprise file data, they do not have the metadata.
  • Trees:- In GIT, trees can be understood as objects representing a directory. They hold various file versions or blobs.
  • Commits:- It represents the current state of a repository. Commit objects include a pointer that allows the developer to go to the parent commit and track history.
  • Branches:- GIT has a master branch by default. However, you can also create sub-branches to work on a different feature. Once you are done working on the feature, you can merge it with the main branch.
  • Tags:- Developers use tags to give a specific name to a particular version of repositories. They are similar to the branches. However, you do not have to modify a tag even while creating a different commit.
  • Clone:- It mirrors the complete repository and checks out the working copy.
  • Pull:- This operation is used to synchronise changes between the local and the remote repositories. It copies the changes made in the remote repository to the local one.
  • Push:- Contrary to the pull operation, the push command copies changes made in the local repository to the remote one.
  • HEAD:- You can understand HEAD as a pointer in GIT that points towards the latest commit. Whenever a new commit is made, the HEAD gets updated automatically.
  • Revision:- These are known as the source codes or the previous version of the commit.
  • URL:- It is a link that represents the location of the GIT repository.

GIT Basic Commands

Here are a few GIT commands that you must remember to perform the core functions in GIT:

  • GIT help command:- This command aims to find out information about other commands. In simple words, if you do not know what a particular command does or how it works, you can use the GIT help command to get information.
  • GIT Clone:- You can use the clone command to create a snapshot of the remote repository on the local database.
  • GIT Fetch:- This command shows the latest changes in the remote repository.
  • GIT Commit:- It creates a snapshot of the files in the local index that need to move to the remote repository. Click to learn more about Git Commands.

Step by Step Guide to Learn GIT

  • How to download and install GIT on Windows?

There are various ways to install GIT on Windows. Since GIT is an open-source platform, you can download the latest version GIT directly from the official website for free.  Another option is to install GitHub on Windows, which already has a command-line version. The third option is to install GIT from the source directly. However, you will also require GIT libraries like expat, Zlib, and curl for this purpose.

Explore Our Software Development Free Courses

  • Setting up

After downloading or installing the GIT software on your desktop, you have to customise the GIT environment by setting the GIT configuration tools like setting identity and editor, checking the personal settings, and getting help.

To set the identity, you need to enter your name and email address that the GIT commits will use. The next step is to change the GIT editor. If you wish to use the default editor in your text, you do not have to configure the GIT editor.

You can check all your settings on GIT in one go by using the config list demand. It will show you all the settings that you have made on GIT.

Explore our Popular Software Engineering Courses

  • Creating or initialising repository in GIT

You can start using GIT after you create or initialise a repository. First, you need to go to the directory in which you want to create a repository and open up the terminal (Git CMD). Now, you have to execute the command ‘git init’. The command creates a folder called ‘.git’, which serves as the repository’s metadata. 

In-Demand Software Development Skills

  • Cloning a repository

You can access a remote repository on the local system by cloning it using the command .git clone <remote URL>. You can work on the local file, make changes and then copy the changes to the remote repository using the push command.

  • Creating a commit

Commit is a snapshot of the history of all the changes made in the repository. You have to choose specific files that need to be committed. The committing process involved adding references or messages for the changes you have made to understand the modifications later. To commit a file, you have to open the repository and execute the git commit command. A text editor appears on the screen. Next, you need to type a commit message. It is best to follow the 50/72 rule while writing the message. It means writing a 50 characters summary in the first line and using 72 characters for the explanation.

  • Viewing history

You have to use the ‘git log command’ to view the history of a repository. It will show you all the changes made to the repository in reverse chronological order, the author’s name and email, the commit message, and the exact time of creation.

  • Creating and merging branches
Ads of upGrad blog

GIT allows working on different sub-branches for performing various functions. You can create a new branch by executing the command git branch <branch-name>. To merge the sub-branches with the master branch, you need to place the head in the master branch. It indicates that the sub-branch will move there. Then, you need to execute the merge command git merge <branch name>.

Read our Popular Articles related to Software Development

Conclusion

Even though GIT is pretty technical compared to other distributed version control systems, it is widely used due to its unique features. Therefore, if you are keen on building a career in software development, it is crucial to know how GIT works. You can learn GIT in-depth by pursuing a Master of Science in Computer Science from upGrad offered by Liverpool John Moores University.

Profile

upGrad

Blog Author
We are an online education platform providing industry-relevant programs for professionals, designed and delivered in collaboration with world-class faculty and businesses. Merging the latest technology, pedagogy and services, we deliver an immersive learning experience for the digital world – anytime, anywhere.

1What is GIT?
GIT is a distributed version control system that developers use to track multiple changes in a code. It creates a history of each version of the code.
2What are the advantages of using GIT?
GIT is one of the most popular version control systems due to its efficiency in large-scale projects. One of its significant advantages is that it allows creating multiple branches, which allows many developers to work independently on a single project.
3How to create repositories in GIT?
You can initialise a GIT repository by going to the directory and executing the git init command.

Suggested Blogs

What is Network Address Translation (NAT) in Networking? A Ultimate Guide
1500
NAT Network Address Translation is a networking firewall that enables your IP address to global computers. It’s a firewall that eradicates traff
Read More

by Keerthi Shivakumar

06 Apr 2023

What is Full Stack Developer &#038; what are the most demanded FSD skills
1500
Software developers aiming to upgrade their skills must ascertain that they are the most sought-after in the tech industry. The search for becoming a
Read More

by Keerthi Shivakumar

30 Mar 2023

7 Top Technical Skills to Master in 2023
1500
Sharpening your technical skills can help you become any recruiter’s preferred choice. Although there may be several open positions in the IT field, m
Read More

by Pavan Vadapalli

17 Mar 2023

Transient in java: What is, How Does it Work?
1500
What is Transient in java? Transient in java is a variable modifier used to avoid serialization. In other words, if an object of a data structure is
Read More

by Pavan Vadapalli

23 Feb 2023

Implementing the Fibonacci Sequence in Python
1500
Python is a powerful and versatile multi-purpose programming language that facilitates the implementation of Artificial Neural Networks and supports N
Read More

by Pavan Vadapalli

23 Feb 2023

MS in the UK for Indian Students: Top Universities, Fees, Eligibility, Career Scope
1505
Introduction  Thousands of students from India go abroad every year to pursue their Master’s degree in another country, and the UK is one of the most
Read More

by Pavan Vadapalli

12 Feb 2023

Selection Sort in Python: Explained with Examples
1500
Selection sort in Python is an in-place sorting algorithm. In this sorting algorithm, only one swap happens for every pass through the list. The algor
Read More

by Pavan Vadapalli

09 Feb 2023

Thread Priority in Java: Explained with Examples
1500
Fundamentals of Thread Priority in Java: Though concurrent execution of threads is conceptually true, it is impractical. Most of the computer configu
Read More

by Pavan Vadapalli

04 Feb 2023

Java TreeMap with Examples
1500
TreeMap is a form of map implementation in Java. It works on the red and black tree data structure. Let us have a detailed look at different aspects o
Read More

by Pavan Vadapalli

02 Feb 2023