How Git Version Control Works

watch 6m, 36s
views 2

12:48, 25.05.2026

Article Content
arrow

  • Introduction to Git
  • Understanding GitHub
  • Getting Started with Git
  • Terminal vs. Graphical Interface (GUI)
  • Setting Up Your Project Folder for Git
  • Initializing a Git Repository
  • Git Repository Explained
  • Collaborating with Others Using Git
  • How Git Monitors File Changes
  • What is a Commit in Git?
  • How to Create a Commit
  • Overview of a Standard Git Workflow
  • Step 1 – Editing Your Files
  • Step 2 – Staging the Changes
  • Step 3 – Committing the Changes
  • Exploring Git Commit History
  • What Are Git Branches?
  • Final Thoughts

Git version control is necessary for developers to collaborate better and track various code versions.

If the team is working on a specific project for a prolonged time period, then it will be necessary to track all the possible changes for better troubleshooting, and Git can be a great system for this purpose.

However, if you have never used Git before, it might sound extremely overwhelming topic. So, we decided to simplify the process a little bit and discuss some possible questions and difficult moments for you.

Introduction to Git

Git is a specific system that should be downloaded on your machine for working with coding projects individually or with a team of other developers.

To check where Git is installed on your machine, use the following command:

git –version

In case Git is already installed, you will see its version after typing this command. If there is no Git on your machine, then just visit the official website of Git and follow the simple instructions.

Understanding GitHub

GitHub is needed for hosting Git projects on the cloud. This is just a product for hosting, and there are other hosting services that are similar to GitHub, for instance, GitLab.

Getting Started with Git

Terminal vs. Graphical Interface (GUI)

Git can be managed in the most suitable way for any client. For some users, it will be through the terminal and usage of the commands, and for others, it will be through the GUI, such as GitKraken.

In case you decided to use the terminal, then start by reviewing some basic and needed commands. There is detailed documentation regarding the commands on the official website, and you don’t need to learn them; just check the needed commands when there is necessary.

Those users who prefer a more visual experience should better choose a GUI.

Further on, we will mostly focus on the usage of the terminal, but the steps are fairly similar to the GUI users as well.

Setting Up Your Project Folder for Git

For the usage of Git, you should have a project that needs to be version-controlled. If you are starting a new project, then create a folder and navigate through the process through the terminal. The creation of the folder can be done with the command mkdir.

If the project is already created, then we just navigate into it in the terminal.

Initializing a Git Repository

When we are in the project folder, for Git usage, it is necessary to initialize the repository with git init. Once you type the command in the terminal and press Enter, it will be executed.

Lots of processes in Git are made behind the scenes, and to check the hidden files, you will need to follow the next step. On Mac, users should select Command+Shift+Dot to review the hidden files. For the same purpose, in the Windows OS system, it is necessary to change the view settings.

To check the hidden files in the terminal, use:

ls -a

Git Repository Explained

To make it simpler, the repository is a .git folder that is inside the project folder. Such a system is needed to track all the changes to this specific project. The repository that is on your machine is called the local one.

Once we start using GitHub or other similar hosting services and upload this local repository there, then it is already a remote repository. This remote repository is crucial for the regular backups as well as for easy collaboration with other developers on the same project.

Collaborating with Others Using Git

For the other developers to access a specific project, they can download/clone the remote repository from the hosting service. Once they download the project, they will have access to the local repository.

In one big project, all the involved developers have their local access on the machine. To add some details and share their work, it is possible to add these details to the remote repository.

How Git Monitors File Changes

To save various versions of the same projects, there should be made commits.

What is a Commit in Git?

A commit in Git is the same as a version of the project. It includes the standalone version of the project and references to the folders and files.

How to Create a Commit

For the understanding and creation of the commit, it is crucial to know about various spaces in Git, such as the staging area, the working directory, and the commit history.

The working directory is the content of the project folder. It functions as the workbench where you can edit, add, or delete the needed parts or files.

The staging area is like a space for the rough draft. This is like a place where it is possible to update/add file versions or delete something, so that you can easily select what will be in the following version of the project or commit. This space is represented by the index file.

As for the commit history, it is a place where commits live, and they are stored in the objects folder. Both the commit history and the staging area are part of the repository.

Overview of a Standard Git Workflow

Step 1 – Editing Your Files

If you have created a new project that is called, for instance, skills, you can also make a simple text file and name it chapter0. The creation of this file may be done directly in the terminal or with the help of a text editor. To do it directly in the terminal, you can use touch chapter0.txt.

In the current project, it is possible to add, edit, or delete the files depending on necessity. Also, after that, it is possible to use git status. This command is needed to specify the state of the staging area and the working directory and determine the differences between them.

Once the new file is added to the directory, and to make it a tracked file, use git add. Which we will discuss more in the following step.

Step 2 – Staging the Changes

To add updated or new files to the staging, we need to use git add. In case there are some files that we don’t need to include in the next commit, then we don’t add them to the staging area.

Once we add the file to the staging area with git add command, and then with the usage of git status so we can detect whether the file is added to the staging area.

The files are not moved to the staging area, they are copied over from the working directory.  

Step 3 – Committing the Changes

To actually make a commit, it is necessary to use the git commit -m command and pass the commit message.

To list all the commits in the project, it is necessary to use the git log command. Every commit has a 40-character commit hash that can include numbers and letters and is used as the name for the commit.

Exploring Git Commit History

The repository includes several commits. In the simplest possible scenario, each commit has a parent commit that was the initial one.

Of course, there are more complex scenarios where there are several merges and branches, but we are not diving into this topic here.   

What Are Git Branches?

Git branch is a pointer to the commit. The default branch is called main or master branch. The branch is a pointer to the commit, and we can literary check it by entering .git folder, refs folder, heads folder, and master. Inside this file, there is a hash of the commit.

To check all the branches in the terminal, use:

git branch  

Branches simplify lots of processes, making it much easier to work on several features and with various developers on the team.

Final Thoughts

In the article, we only covered the important basics of Git, and if you want to learn more, there is plenty of information online that you can check out.

Share

Was this article helpful to you?

VPS popular offers

-10%

CPU
CPU
4 Xeon Cores
RAM
RAM
2 GB
Space
Space
30 GB SSD
Bandwidth
Bandwidth
Unlimited
10Ge-KVM-SSD 2048 Linux

30.3 /mo

/mo

Billed annually

-10%

CPU
CPU
6 Xeon Cores
RAM
RAM
8 GB
Space
Space
100 GB SSD
Bandwidth
Bandwidth
Unlimited
MT5 KVM 8192 Windows

29.99 /mo

/mo

Billed annually

-10%

CPU
CPU
4 Epyc Cores
RAM
RAM
4 GB
Space
Space
50 GB NVMe
Bandwidth
Bandwidth
Unlimited
aiKVM-NVMe 4096 Linux

17.08 /mo

/mo

Billed annually

-10%

CPU
CPU
4 Epyc Cores
RAM
RAM
4 GB
Space
Space
50 GB NVMe
Bandwidth
Bandwidth
Unlimited
KVM-NVMe 4096 Linux

16.45 /mo

/mo

Billed annually

-10%

CPU
CPU
6 Xeon Cores
RAM
RAM
8 GB
Space
Space
100 GB SSD
Bandwidth
Bandwidth
Unlimited
KVM-SSD 8192 Linux

25.85 /mo

/mo

Billed annually

-10%

CPU
CPU
3 Epyc Cores
RAM
RAM
2 GB
Space
Space
20 GB NVMe
Bandwidth
Bandwidth
Unlimited
KVM-NVMe 2048 Linux

8.8 /mo

/mo

Billed annually

-15.5%

CPU
CPU
6 Xeon Cores
RAM
RAM
8 GB
Space
Space
100 GB SSD
Bandwidth
Bandwidth
80 Mbps
DDoS Protected SSD-KVM 8192 Linux

95 /mo

/mo

Billed annually

-10%

CPU
CPU
3 Epyc Cores
RAM
RAM
2 GB
Space
Space
25 GB NVMe
Bandwidth
Bandwidth
Unlimited
wKVM-NVMe 2048 Windows

9.9 /mo

/mo

Billed annually

-10%

CPU
CPU
10 Xeon Cores
RAM
RAM
64 GB
Space
Space
300 GB SSD
Bandwidth
Bandwidth
Unlimited
KVM-SSD 65536 Linux

134.99 /mo

/mo

Billed annually

-9.7%

CPU
CPU
10 Epyc Cores
RAM
RAM
64 GB
Space
Space
300 GB NVMe
Bandwidth
Bandwidth
Unlimited
wKVM-NVMe 65536 Windows

139.49 /mo

/mo

Billed annually

Other articles on this topic

What are firewalls
What are firewalls
cookie

Accept cookies & privacy policy?

We use cookies to ensure that we give you the best experience on our website. If you continue without changing your settings, we'll assume that you are happy to receive all cookies on the HostZealot website.