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:- Which version is the latest?
- Which version introduced a bug?
- How can I restore an earlier working version?
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
Types of Version Control
Local Version Control
History is stored only on your computer. Advantages- Fast
- Simple
- 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
- Requires network connectivity
- Server failure affects everyone
- 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
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
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.Working Directory
The Working Directory is your project folder where you create, edit, rename, and delete files.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:- 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
- Backup
- Collaboration
- Sharing code
Creating a Local Repository
Suppose your project is:.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
After
- No commits
- No version history
- No tracked snapshots
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 initcreates a hidden.gitfolder 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.