Skip to main content

The problem Git solves

Why Do We Need Version Control?

Imagine developing a project without Git. To keep different versions, you might create folders like:
After some time, it becomes difficult to answer questions like:
  • Which version is the latest?
  • Which version introduced a bug?
  • How can I restore an earlier working version?
A Version Control System (VCS) solves these problems by maintaining the complete history of your project.

What is Version Control?

Version Control is a system that records changes made to files over time. It helps you:
  • Track changes
  • Restore previous versions
  • Compare versions
  • Collaborate with others
  • Maintain the complete history of a project
Instead of creating multiple copies of a project manually, a Version Control System manages the history automatically.

Types of Version Control

Local Version Control

History is stored only on your computer. Advantages
  • Fast
  • Simple
Limitations
  • No collaboration
  • History is lost if the computer fails

Centralized Version Control

A central server stores the project history. Advantages
  • Easy collaboration
  • Single source of truth
Limitations
  • Requires network connectivity
  • Server failure affects everyone
Examples
  • SVN
  • CVS

Distributed Version Control

Every developer has a complete copy of the repository. Advantages
  • Works offline
  • Full history on every machine
  • Faster operations
  • Better collaboration
Git is a Distributed Version Control System (DVCS).

What is Git?

Git is a Distributed Version Control System that tracks changes by storing snapshots of your project. Git allows you to:
  • Track changes
  • Save versions (commits)
  • Restore previous versions
  • Create branches
  • Merge changes
  • Collaborate with others
Git runs on your local computer and can be used without GitHub.

What is GitHub?

GitHub is a cloud platform that hosts Git repositories. Other Git hosting platforms include:
  • GitLab
  • Bitbucket
  • Azure DevOps

Project

A project is simply a folder containing your source code.
Initially, Git does not track this folder.

Working Directory

The Working Directory is your project folder where you create, edit, rename, and delete files.
These are the files you work with every day.

Repository

A Repository (Repo) is Git’s database that stores the history and metadata of your project. There are two types of repositories.

Local Repository

The repository stored on your computer. Created using:
Stored inside the hidden folder:
The Local Repository stores:
  • Commit history
  • Branches
  • Tags
  • Repository configuration
  • Other Git metadata

Remote Repository

A copy of the Local Repository hosted on a server such as:
  • GitHub
  • GitLab
  • Bitbucket
It is mainly used for:
  • Backup
  • Collaboration
  • Sharing code

Creating a Local Repository

Suppose your project is:
Initialize Git:
Git creates a hidden folder.
The .git folder is your Local Repository.
Note git init only creates an empty Git repository. It does not copy your project files into the repository or create any commits.

Before and After git init

Before

Only your project files exist.

After

The repository now exists, but it contains:
  • No commits
  • No version history
  • No tracked snapshots
Your files are still only in the Working Directory.

Local Repository vs Remote Repository

  • The Local Repository stores your project’s history on your computer.
  • The Remote Repository is a shared copy used for collaboration and backup.
  • GitHub stores a copy of your Local Repository, not your Working Directory.

Common Git Commands

Summary

Key Takeaways

  • Git is a Version Control System, while GitHub is a repository hosting platform.
  • A project starts as a normal folder.
  • Running git init creates a hidden .git folder called the Local Repository.
  • After git init, the repository exists but is still empty.
  • Your project files remain in the Working Directory until they are staged and committed.
  • The Remote Repository is simply a copy of your Local Repository hosted online.