What is Git?
Git is a distributed version control system used in software projects to track changes made to files and code, store different versions, and make it easier for developers to work together on the same project. In English, this concept is called a Distributed Version Control System — DVCS. In simple terms, Git allows developers to track what changes were made to a project, when those changes were made, and who made them. For example, imagine that you are building a website. Today, you add a login page. Tomorrow, you change the design. A few days later, you notice that one of those changes has caused a problem. With Git, you can review the project's change history, determine which code was changed and when, and compare it with a previous state when necessary. Git is widely used in Frontend, Backend, Full-Stack, mobile development, DevOps, and other areas of software development.
What Is Git Used For?
The main purpose of Git is to manage the change history of a software project.
With Git, you can:
- track changes made to code;
- store different versions of a project;
- review previous changes;
- work on new features separately;
- organize the work of multiple developers on the same project;
- combine different code changes;
- synchronize a project with remote platforms such as GitHub.
For example, three developers may work on the same project. One developer may build the login system, another may work on the product page, and a third may develop the payment functionality. Git allows these changes to be developed separately and later combined into the main project.
What Is Version Control?
Version Control is a system for tracking changes made to files and software code over time.
For example, different stages of a project can be imagined like this:
Version 1
↓
Login added
↓
Version 2
↓
Product page added
↓
Version 3
↓
Payment system added
Git helps track these changes as separate versions. This allows developers to see not only the current state of the project but also how it has evolved over time. Version Control is especially important when software is developed by a team.
What Is Distributed Version Control?
Git is a Distributed Version Control System. This means that a developer can store not only the latest version of a repository but also a local copy of its Git history on their own computer.
For example:
Developer A
↓
Local Repository
Developer B
↓
Local Repository
Developer C
↓
Local Repository
↕
Remote Repository
Developers can work in their local repositories, create commits, and later share their changes with a remote repository. This approach is different from centralized version control systems.
What Is a Repository?
A Repository, or repo for short, is a project and its change history managed by Git.
A repository may contain:
- source code;
- images;
- configuration files;
- documentation;
- other project-related files.
To create a Git repository, you can use:
git init
This command turns the current directory into a Git repository.
To download an existing repository to your computer, you can use:
git clone
A repository can generally exist in two main forms:
Local Repository — stored on the developer's computer.
Remote Repository — stored on GitHub, GitLab, or another server or platform.
How Does Git Work?
When working with Git, changes usually go through several stages.
A simplified process looks like this:
Working Directory
↓
Staging Area
↓
Local Repository
↓
Remote Repository
Working Directory is the area where you are currently working on project files. Staging Area is the stage where you choose which changes should be included in the next commit. Local Repository is the local Git repository where created commits and project history are stored. Remote Repository is a repository located on a remote server such as GitHub. Understanding this structure makes it much easier to understand the logic behind Git commands.
What Is git init?
git init is used to create a new Git repository.
For example:
git init
When you run this command inside a project directory, Git prepares that directory for version tracking. A special directory called .git is created.
The .git directory stores:
- Git history;
- branches;
- commits;
- metadata;
- other repository information.
Accidentally deleting the .git directory may cause the Git history of the repository to be lost.
What Is git status?
git status shows the current state of the repository.
For example:
git status
With this command, you can see:
- which files have been modified;
- which files have been added to the Staging Area;
- which files are not yet being tracked by Git.
git status is one of the most useful commands for beginners because it helps you understand what is happening in the repository at every stage.
What Is git add?
After making changes to a file, those changes are not automatically included in a commit. First, the changes need to be added to the Staging Area.
For example:
git add index.html
adds only the changes in index.html to the Staging Area.
To add all relevant changes, you can use:
git add . This allows developers to control which changes will be included in the next commit.
What Is a Commit?
A Commit is a record of changes made at a specific point in the project's history. You can think of a commit as a checkpoint in the history of a project.
For example:
git commit -m "Add login page"
This command records the changes currently in the Staging Area as a commit.
Later, another change may be made:
git commit -m "Fix login validation"
This creates a history of changes in the project. A good commit message should clearly and briefly describe what was changed.
What Is git log?
git log displays the commit history of a repository.
For example:
git log
can show:
- the author of each commit;
- the date;
- the commit identifier;
- commit messages.
For a shorter view, you can use:
git log --oneline
This makes it easier to review the development history of the project.
What Is a Branch?
A Branch is a separate development line that allows developers to work on changes without directly modifying the main codebase.
For example, the main branch may be called:
main
For a new login feature, you can create a separate branch called:
feature/login
This allows a developer to work on the new feature without changing the stable version of the main project.
To create a new branch:
git branch feature/login
To switch branches in modern Git:
git switch feature/login
To create a new branch and immediately switch to it:
git switch -c feature/login
What Are main and master?
The main branch of a Git repository can have different names.
In the past, many repositories used:
master
as the main branch name.
Today, many new projects commonly use:
main
However, Git does not require the primary branch to be called main or master. A different name may be used depending on the project's configuration.
What Is Merge?
Merge is the process of combining changes from one branch into another.
For example:
main
│
├─────────────┐
│ │
│ feature/login
│ │
└──── merge ←─┘
After the login system has been completed in the feature/login branch, its changes can be merged into the main branch. This process allows teams to work on different features in parallel.
What Is a Merge Conflict?
Sometimes two branches modify the same part of the same file in different ways. When Git cannot automatically determine which version should be used, a Merge Conflict occurs.
For example:
Developer A:
Button color → blue
Developer B:
Button color → green
Because the same part of the code was changed differently, Git may require the developer to choose the correct version. Merge Conflicts are a normal part of team-based software development and should be resolved carefully.
What Is the Difference Between Git and GitHub?
Git and GitHub are not the same thing. Git — is a version control system. GitHub — is a platform used to store, share, and manage Git repositories online. Git can work on your computer without GitHub.
For example, even without an internet connection, you can work with a local repository using:
git init
git add .
git commit -m "Initial commit"
GitHub, on the other hand, provides features such as:
- Remote Repositories;
- Pull Requests;
- Issues;
- Actions;
- collaboration tools.
A simple comparison:
Git → manages the history of changes.
GitHub → provides a platform for sharing Git repositories and working as a team.
What Is a Remote Repository?
A Remote Repository is a Git repository located outside your local computer. It may be stored on GitHub, GitLab, or another server.
To see the list of configured remotes:
git remote -v
To add a new remote:
git remote add origin https://github.com/user/project.git
Here, origin is one of the standard names commonly used for a remote repository.
What Is git clone?
git clone is used to download a copy of an existing Git repository to your computer.
For example:
git clone https://github.com/user/project.git
This command downloads both the project files and the Git repository history to your local computer.
Clone is especially useful when:
- joining an existing development team;
- starting work on an open-source project.
What Is git push?
git push is used to send commits created in the local repository to a remote repository.
For example:
git push origin main
This sends the commits from the local main branch to the origin remote. After the push, other team members can see those changes in the remote repository.
What Is git fetch?
git fetch retrieves new information from a remote repository and stores it in the local Git repository, but it does not automatically integrate those changes into the current branch.
For example:
git fetch origin
can retrieve information about new branches and commits from the remote repository. The advantage of this command is that developers can first review the remote changes and then decide how to integrate them into their own branch.
What Is git pull?
git pull retrieves changes from a remote repository and updates the local branch. In simplified terms, git pull usually fetches remote changes and then attempts to integrate them into the current branch.
For example:
git pull origin main
can bring new changes pushed by other developers to the main branch into the local project.
What Is the Difference Between git fetch and git pull?
git fetch retrieves remote changes but does not automatically integrate them into the current branch. git pull retrieves the changes and then attempts to integrate them into the local branch.
A simple comparison:
git fetch → retrieve the information and review it first.
git pull → retrieve the information and update the local branch. Understanding the difference between these two commands is important when working in a team.
What Is the Difference Between git push and git pull?
git push sends changes from the local repository to the remote repository. git pull brings changes from the remote repository into the local project.
A simple direction:
Local Repository
↓
git push
↓
Remote Repository
↓
git pull
↓
Local Repository
These commands help synchronize the developer's local work with the remote repository shared by the team.
What Is .gitignore?
.gitignore is a special file that defines files and directories that Git should not track.
For example:
node_modules/
.env
dist/
can be included in .gitignore. Large dependency directories such as node_modules generally do not need to be stored in the repository.
The .env file may contain sensitive information such as:
- API keys;
- database passwords;
- other credentials.
It is important not to push such information to a public repository.
What Is HEAD?
In Git, HEAD is a special reference that points to the commit or branch position you are currently working on. In most cases, HEAD points to the latest commit of the current branch.
For example, if you are working on the main branch:
HEAD → main → latest commit
The concept of HEAD becomes more important when working with:
- checkout;
- reset;
- rebase;
- Git history.
What Is git diff?
git diff is used to show the differences between changes.
For example:
git diff
can help display uncommitted changes.
With this command, you can see which lines were:
- added;
- removed;
- modified.
Checking code changes with git diff before committing is considered a good practice.
What Is the Difference Between Git revert and reset?
Git provides different mechanisms for working with previous changes.
git revert creates a new commit that reverses the changes made by a specific commit. This approach is often safer in a shared repository because it does not rewrite the existing history. git reset, on the other hand, can change which commit a branch points to and, in some cases, can also affect the staging area and working tree.
Using reset, especially with:
--hard
can result in lost changes. For this reason, it is important to understand how these commands affect repository history before using them.
What Is Git Rebase?
Rebase is a Git operation that allows commits from one branch to be reapplied on top of another base. For example, if a feature branch is behind the main branch, rebase can place the feature commits on top of the newer state of main. Rebase can create a more linear commit history. However, rebasing commits that have already been shared with other developers can cause problems because it rewrites repository history. For this reason, it is not recommended to use rebase on shared branches without understanding how it works.
Why Is Git Important for Developers?
Real software projects are constantly changing. New features are added, bugs are fixed, code is refactored, and multiple developers may work on the same project.
Git makes it possible to manage these changes systematically.
With Git, developers can:
- see which code was changed and when;
- create branches for different features;
- commit their changes;
- share changes with team members.
Git can also be useful during Debugging. For example, it is possible to investigate after which commit a particular problem appeared.
Is Git Only for Developers?
Git is mainly associated with software development, but it is not designed exclusively for source code. Technically, Git can be used to track the change history of different text-based files.
However, it is especially effective in programming because it allows developers to:
- compare source code changes line by line;
- create branch-based workflows.
What Are the Most Commonly Used Git Commands?
At the beginner level, knowing the following Git commands provides a strong foundation:
git init
git clone
git status
git add
git commit
git log
git branch
git switch
git merge
git fetch
git pull
git push
git diff
Instead of simply memorizing all of these commands, it is more important to understand what purpose each of them serves within the Git workflow.
Where Should You Start Learning Git?
When learning Git, you do not need to begin with complex commands.
At first, learning a simple workflow is enough:
Create a project
↓
git init
↓
Make changes to files
↓
git status
↓
git add
↓
git commit
After that, you can learn how to work with a Remote Repository.
For example:
GitHub Repository
↓
git clone
↓
Make changes
↓
git add
↓
git commit
↓
git push
At the next stage, you can move on to concepts such as:
- Branch;
- Merge;
- Merge Conflict;
- Pull Request;
- Fetch;
- Rebase.
The best way to learn Git is by using it in real projects. Managing your personal projects with Git and publishing them on GitHub can both improve your Git skills and help you build a programming portfolio. If you want to learn Git, GitHub, and other modern programming tools through real-world projects, you can explore JET Academy's Frontend, Full-Stack and Java Backend Programming Courses.
