Git Tutorial For Beginners: Learn Git from Scratch
By Mukesh Kumar
Updated on Feb 24, 2025 | 10 min read | 6.2k views
Share:
For working professionals
For fresh graduates
More
By Mukesh Kumar
Updated on Feb 24, 2025 | 10 min read | 6.2k views
Share:
Table of Contents
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.
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
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:
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.
Here are a few GIT commands that you must remember to perform the core functions in GIT:
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.
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.
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.
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.
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.
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.
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>.
Keep scrolling through our Git tutorial to learn how to perform a few things:
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.
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.”
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.
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.
Get Free Consultation
By submitting, I accept the T&C and
Privacy Policy
India’s #1 Tech University
Executive PG Certification in AI-Powered Full Stack Development
77%
seats filled
Top Resources