Git - Introduction
Git is a distributed version control system that tracks changes in files and coordinates work among multiple people. Created by Linus Torvalds in 2005 for Linux kernel development, Git has become the standard tool for software development worldwide.
What is Version Control?
Version control is like having an unlimited "undo" button for your project, plus the ability to work with others without stepping on each other's toes. Imagine you're writing a book with multiple authors:
- Without version control: You email documents back and forth, create files like "chapter1_final.doc", "chapter1_REALLY_final.doc", "chapter1_final_v2.doc"
- With Git: Everyone can work simultaneously, all changes are tracked, and you can see exactly who changed what and when
Why Git Instead of Other Systems?
Distributed vs Centralized
Central Server ← → Developer 1
← → Developer 2
← → Developer 3
Developer 1 ← → Remote Repo ← → Developer 2
↑ ↑
↓ ↓
Local ← → Local
Repo Repo
Benefits of Git's distributed approach:
- Work offline - full history available locally
- No single point of failure
- Fast operations (most commands are local)
- Flexible workflows
- Complete backup in every clone
Core Git Concepts
The Three States
Git has three main states that your files can be in:
1. Modified → 2. Staged → 3. Committed
(working) (index) (.git)
- Modified: You've changed files but haven't saved them to Git yet
- Staged: You've marked modified files to go into your next snapshot
- Committed: Files are safely stored in your local Git database
The Repository Structure
my-project/
├── .git/ ← Git's database (don't touch!)
├── README.md ← Your files (working directory)
├── src/
│ └── main.js
└── package.json
Basic Git Workflow
Here's the fundamental workflow you'll use thousands of times:
# Edit some files in your project
$ echo "Hello World" > README.md
# Add files to staging area
$ git add README.md
# Save snapshot to repository
$ git commit -m "Add hello world to README"
[main 7f8a9b2] Add hello world to README
1 file changed, 1 insertion(+)
create mode 100644 README.md
Git vs GitHub vs GitLab
- Git: The version control software that runs on your computer
- GitHub: Microsoft's cloud service for hosting Git repositories
- GitLab: Alternative hosting service (can be self-hosted)
- Bitbucket: Atlassian's Git hosting service
Who Should Use Git?
🟢 Beginners
- Anyone writing code, documents, or managing projects
- Students learning programming
- Writers collaborating on documents
- Designers tracking asset changes
🟡 Professionals
- Software developers (individual or team)
- DevOps engineers managing infrastructure as code
- Technical writers maintaining documentation
- Data scientists tracking experiments
🔴 Architects & Leaders
- Enforcing code quality and review processes
- Designing branching strategies for teams
- Integrating with CI/CD pipelines
- Managing large-scale, multi-team projects
What You'll Learn in This Tutorial
This comprehensive tutorial covers every Git command with practical examples:
🟢 Beginner Level
- Installation and basic setup
- Core workflow: add, commit, push, pull
- Basic branching and merging
- Working with remote repositories
🟡 Intermediate Level
- Advanced branching strategies
- Resolving merge conflicts
- Undoing changes and recovery
- Collaboration workflows
🔴 Advanced Level
- Rebasing and history rewriting
- Git internals and object model
- Hooks and automation
- Performance optimization
🟣 Expert Level
- Custom merge drivers
- Repository maintenance
- Enterprise workflows
- Git server administration
Prerequisites
- Computer skills: Basic familiarity with command line/terminal
- Text editor: Any editor (VS Code, Vim, Notepad++ recommended)
- Mindset: Willingness to practice commands and make mistakes
Common Misconceptions
- ❌ "Git is too complex for beginners" → ✅ The basics are simple, advanced features are optional
- ❌ "Git is only for programmers" → ✅ Useful for any text-based work
- ❌ "I'll lose my files" → ✅ Git makes it nearly impossible to lose committed work
- ❌ "I need to understand everything first" → ✅ Start with basic workflow, learn incrementally
Success Metrics
After this introduction, you should understand:
- ✅ What version control is and why it matters
- ✅ How Git differs from other systems
- ✅ The three states (working, staged, committed)
- ✅ Basic Git workflow concept
- ✅ Difference between Git and GitHub
Next Steps
Ready to get started? Next, we'll install Git and configure it for your first project: