Blog_Banner_Asset
    Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconSoftware Developmentbreadcumb forward arrow iconGit Tutorial For Beginners: Learn Git from Scratch

Git Tutorial For Beginners: Learn Git from Scratch

Last updated:
24th Jun, 2023
Views
Read Time
10 Mins
share image icon
In this article
Chevron in toc
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

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. 

Ads of upGrad blog

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. 

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.

Frequently Asked Questions (FAQs)

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.

Explore Free Courses

Suggested Blogs

Top 14 Technical Courses to Get a Job in IT Field in India [2024]
90952
In this Article, you will learn about top 14 technical courses to get a job in IT. Software Development Data Science Machine Learning Blockchain Mana
Read More

by upGrad

15 Jul 2024

25 Best Django Project Ideas &#038; Topics For Beginners [2024]
143863
What is a Django Project? Django projects with source code are a collection of configurations and files that help with the development of website app
Read More

by Kechit Goyal

11 Jul 2024

Must Read 50 OOPs Interview Questions &#038; Answers For Freshers &#038; Experienced [2024]
124781
Attending a programming interview and wondering what are all the OOP interview questions and discussions you will go through? Before attending an inte
Read More

by Rohan Vats

04 Jul 2024

Understanding Exception Hierarchy in Java Explained
16879
The term ‘Exception’ is short for “exceptional event.” In Java, an Exception is essentially an event that occurs during the ex
Read More

by Pavan Vadapalli

04 Jul 2024

33 Best Computer Science Project Ideas &#038; Topics For Beginners [Latest 2024]
198249
Summary: In this article, you will learn 33 Interesting Computer Science Project Ideas & Topics For Beginners (2024). Best Computer Science Proje
Read More

by Pavan Vadapalli

03 Jul 2024

Loose Coupling vs Tight Coupling in Java: Difference Between Loose Coupling &#038; Tight Coupling
65177
In this article, I aim to provide a profound understanding of coupling in Java, shedding light on its various types through real-world examples, inclu
Read More

by Rohan Vats

02 Jul 2024

Top 58 Coding Interview Questions &amp; Answers 2024 [For Freshers &amp; Experienced]
44560
In coding interviews, a solid understanding of fundamental data structures like arrays, binary trees, hash tables, and linked lists is crucial. Combin
Read More

by Sriram

26 Jun 2024

Top 10 Features &#038; Characteristics of Cloud Computing in 2024
16289
Cloud computing has become very popular these days. Businesses are expanding worldwide as they heavily rely on data. Cloud computing is the only solut
Read More

by Pavan Vadapalli

24 Jun 2024

Top 10 Interesting Engineering Projects Ideas &#038; Topics in 2024
43094
Greetings, fellow engineers! As someone deeply immersed in the world of innovation and problem-solving, I’m excited to share some captivating en
Read More

by Rohit Sharma

13 Jun 2024

Schedule 1:1 free counsellingTalk to Career Expert
icon
footer sticky close icon