What is Git?
Git is a distributed version control system that tracks changes in files over time. It allows multiple people to collaborate on projects without overwriting each other’s work.
Why Version Control Matters
Version control helps you:
- Track every change made to your code
- Revert to previous states if something breaks
- Collaborate with others without conflicts
- Maintain a complete history of your project
Centralized vs Distributed
Unlike centralized systems (like SVN) where there’s one main server, Git gives every developer a full copy of the repository. This means:
- Work offline without issues
- Faster operations (no network needed)
- Built-in backup on every clone
What is a Repository?
A repository (or “repo”) is a directory that Git tracks. It contains:
- Your project files
- A
.git/folder with all tracking data
git --version
# git version 2.42.0
What is a Commit?
A commit is a snapshot of your project at a specific moment. Each commit has:
- A unique hash (like
a1b2c3d) - A message describing the change
- The author and timestamp
Best Practices
- Start with
git initorgit cloneto create a repository - Commit often with clear messages
- Use branches for experimental work
- Never commit sensitive data (passwords, keys)
Common Mistakes
- Forgetting to initialize Git before making changes
- Committing too many changes at once
- Using vague commit messages like “fix” or “update”
- Not backing up your repository regularly