Git — Introduction
What is Git?
Git is a distributed version control system. It tracks changes to files over time, lets you recall specific versions later, and enables multiple people to work on the same project without overwriting each other's work.
Created by Linus Torvalds in 2005 (to develop Linux), Git is now the most widely used version control system in the world.
Why Version Control?
Imagine writing a research paper without saving versions:
- "report_final.doc"
- "report_final_v2.doc"
- "report_final_ACTUALLYfinal.doc"
- "report_final_send_to_professor.doc"
This is chaos. Git solves this elegantly:
git log
# Shows every version ever saved, with dates, messages, and authors
What Git Tracks
- File changes — what was added, removed, or modified
- Who made changes — author name and email
- When changes happened — timestamps
- Why changes were made — commit messages
The Three States
Git has three main states for your files:
| State | Description |
|---|---|
| Working Directory | Your actual files on disk |
| Staged | Changes marked for the next commit |
| Committed | Changes saved to the Git history |
# See the status
git status
Basic Workflow
# 1. Make changes to files
echo "Hello, World!" > readme.txt
# 2. Stage changes
git add readme.txt
# 3. Commit changes
git commit -m "Add readme file"
# 4. View history
git log --oneline
The Repository
A Git repository (.git folder) contains the entire history of your project:
my-project/
├── .git/ ← Git repository (don't touch!)
├── src/
│ └── app.js
├── index.html
└── package.json
The .git folder is hidden by default. It stores:
- All committed snapshots
- Branch and tag information
- Configuration settings
- Remote repository URLs
Local vs Remote
- Local repository — on your computer
- Remote repository — on a server (GitHub, GitLab, etc.)
# Clone a remote repo
git clone https://github.com/user/repo.git
# Check remote
git remote -v
Your First Repository
# Create a new project
mkdir my-project
cd my-project
# Initialize Git
git init
# Create a file
echo "# My Project" > README.md
# Stage and commit
git add README.md
git commit -m "Initial commit"
# Check the log
git log --oneline
# abc1234 (HEAD -> main) Initial commit
Common Commands
| Command | Purpose |
|---|---|
git init | Create a new repository |
git clone <url> | Copy a remote repository |
git status | Show working directory status |
git add <file> | Stage a file |
git commit -m "msg" | Save staged changes |
git log | Show commit history |
git push | Upload to remote |
git pull | Download from remote |
Git vs Other Tools
| Feature | Git | Dropbox | Google Drive |
|---|---|---|---|
| Version history | Full | Limited | Limited |
| Branching | Yes | No | No |
| Offline work | Yes | No | Partial |
| Speed | Very fast | Slow | Slow |
| Merge conflict resolution | Yes | No | No |
Common Mistakes
- Not committing often — commit early, commit often
- Bad commit messages — "fixed stuff" tells you nothing
- Committing secrets — never commit passwords, API keys
- Not using .gitignore — don't track build files, dependencies
Best Practices
- Commit early and often
- Write clear, descriptive commit messages
- Use
.gitignoreto exclude unnecessary files - Pull before you push
- Create branches for new features
- Never force-push to shared branches
Mini Practice
- Create a new repository with
git init - Add a file and make your first commit
- Make changes and commit again
- View the commit log
- Check the status between each step
Up Next
Next: Getting Started →
Related Topics
Frequently Asked Questions about Introduction
What is Introduction in Git?
Introduction is a fundamental concept in Git. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Introduction?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Introduction.
Why is Introduction important in Git?
Introduction is essential for Git development. Understanding this concept will help you write better code and solve real-world problems more effectively.