Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
KnowledgeHut upGradKnowledgeHut upGradBackend Development Bootcamp
  • Self-Paced
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

Git Tutorial For Beginners: Learn Git from Scratch

Updated on 03 July, 2023

6K+ views
10 min read

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.

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.

  • 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.

  • 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. 

  • 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

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>.

Git Commands Tutorial: Important Actions to Know

Keep scrolling through our Git tutorial to learn how to perform a few things:

  • Adding a New File to the Repository

You can include a new file in your repository with the help of a text editor or the touch command. You can use the command ‘touch newfile.txt’ to create and save a blank file titled newfile-.txt. 

After you have included or edited files in a folder with a Git repo, Git will find out that the file is present inside the repo. 

But Git won’t be tracking the file as long as you give that specific command. Remember that Git will only save or manage files that it tracks. Therefore, you should send out a command that you want Git to keep track of that new file. 

  • Pushing a Branch to GitHub

A proper Git tutorial for beginners will help you push a branch commit to a new GitHub repo. It ensures that the modifications you make are visible to other people. In case they are approved by the owner of the rep, you will be able to merge the changes into a primary branch. 

When you need to push changes onto a new branch on GitHub, you will have to run Git push origin your branch name. After that, you will automatically find the branch on the remote repository. 

mnelson:myproject mnelson$ git push origin my-new-branch

Counting objects: 3, done.

Delta compression using up to 8 threads.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (3/3), 313 bytes | 0 bytes/s, done.

Total 3 (delta 0), reused 0 (delta 0)

To https://github.com/cubeton/mynewrepository.git

 * [new branch] my-new-branch -> my-new-branch

In this Git commands tutorial, you might be confused regarding the meaning of the word “origin.” After you clone a remote repository to your local machine, Git will form an alias for you. In most cases, this alias is referred to as the “origin.” 

  • Creating a Pull Request (PR)

A pull request or PR is to notify a repo owner that you want to modify their code. It enables them to review the code and ensure that it looks good before incorporating the changes on the primary branch. 

Once you have submitted the PR request, you will notice a big green button with the words ‘Merge pull request.’ When you click on this, your changes will get merged into the primary branch. 

At times, you are the sole owner or co-owner of a repo. In that case, you won’t have to raise a pull request to merge the changes. But it’s more prudent to create a pull request to merge the changes. It will provide you with a full history of the updates that you made. 

After you are done, you should delete the branch to reduce complications. Additionally, you must check whether the commits were merged. You can check the merged commits by clicking on the Commits link present on the first page of your fresh repo. 

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.

Frequently Asked Questions (FAQs)

1. What 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.

2. What 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.

3. How to create repositories in GIT?

You can initialise a GIT repository by going to the directory and executing the git init command.

RELATED PROGRAMS