Git is one of the most essential tools for modern developers. Whether you're working alone or collaborating with a team, Git enables you to track changes, experiment safely, and collaborate effectively.
In this chapter, we explore the fundamentals of version control, understand how Git operates, and learn why it is widely used in modern software development.
What Is Version Control?
Version control is a system that records changes made to files over time.
It allows developers to:
- Restore previous versions
- Compare differences
- Collaborate without overwriting each other's work
- Experiment safely using isolated environments called branches
Version control can be described as the history and backup system of your project.
Why Developers Use Git
Git is a distributed version control system. This means every developer has a full copy of the project history stored locally on their machine.
Key advantages:
- Works offline
- Fast and lightweight
- Easy branching and merging
- Secure experimentation
- Simple collaboration via GitHub, GitLab, or Bitbucket
How Git Organizes Your Project (Explanation Without Diagram)
Git operates using three main areas:
- Working Directory: The place where you edit your actual project files.
- Staging Area (Index): A preparation space where you select the changes you want to include in your next commit.
- Repository (.git folder): The internal database where Git permanently stores your project's history.
The general workflow is explained like this:
You make changes in your Working Directory.
You select which changes to include by moving them into the Staging Area.
Finally, you save those staged changes into the Repository as a commit.
Creating Your First Git Repository
Initialize Git
$ git init
Initialized empty Git repository in /project/.git/This creates the .git folder, which contains the entire version history.
Check Repository Status
$ git status
On branch main
No commits yet
nothing to commitThis command shows what is happening inside your project at any moment.
Add Files to the Staging Area
$ git add index.htmlOr add all files:
$ git add .Make Your First Commit
$ git commit -m "Initial commit"A commit represents a snapshot of your project at a specific point in time.
Git vs GitHub
| Git | GitHub |
|---|---|
| A local version control tool | An online platform for hosting Git repositories |
| Works offline | Requires internet |
| Manages files and version history | Provides collaboration features such as pull requests and issue tracking |
Visual Suggestion (Copyright Safe)
You may create your own custom diagram using simple boxes or arrows in tools such as Excalidraw, Figma, or Whimsical.
This prevents copyright issues and ensures you have lightweight, SEO-friendly visual assets.
Summary
In this chapter, you learned:
- What version control is
- Why Git is essential for developers
- How Git structures a project
- How to initialize and commit for the first time
- The difference between Git and GitHub
Next, we will continue with installing Git and configuring your environment correctly.