01 - Setup and Basics
#01 - Setup and Basics
##What is Git, and Why Should You Care?
Imagine you are writing a 50-page report in Word. You save it as report_final.docx. Then you make more changes: report_final_v2.docx. Then your manager edits it: report_final_v2_manager_edits.docx. After a week you have 10 files and no idea which is actually final.
Git solves this problem for code. Git is a version control system. It tracks every change you make to every file in your project — who changed it, when, and why. You can always go back to any previous version. You can work on different versions in parallel. And multiple people can collaborate without overwriting each other’s work.
Every company you will work at uses Git. It is as fundamental as knowing how to type.
##Installing Git
Check if Git is already installed:
1
git --version
Expected output: git version 2.x.x
If you see “command not found”, install it:
- macOS:
brew install gitor download from https://git-scm.com/downloads - Windows: Download from https://git-scm.com/downloads (includes Git Bash)
- Linux (Ubuntu/Debian):
sudo apt-get install git
##One-Time Configuration
Before you use Git, tell it who you are. Git stamps your name and email on every commit you make — so your teammates know who did what.
1
2
3
git config --global user.name "Priya Sharma"
git config --global user.email "[email protected]"
git config --global init.defaultBranch main
The
--globalflag means: apply this to ALL repositories on this machine. You only need to do this once per computer.
Verify your settings:
1
git config --list
Expected output (partial):
1
2
3
user.name=Priya Sharma
[email protected]
init.defaultBranch=main
##Git’s Three-Area Model
This is the single most important thing to understand. Everything else in Git builds on this.
Think of it like a photographer’s workflow:
1
2
3
4
5
6
Working Directory Staging Area Repository
(your desk) (camera roll) (printed photo album)
You write/edit You select which You save a permanent
files here freely. changes go into snapshot (commit).
Nothing is saved yet. the next snapshot. Can never be lost.
In Git commands:
1
Working Directory git add Staging Area git commit Repository
Working Directory: Your project folder. Edit files here freely.
Staging Area(also called the “index”): A collection zone. You pick exactly which changes to include before committing. This lets you make 5 edits but only commit 2 of them cleanly.
Repository: The permanent history, stored in the hidden .git folder. Every commit is a snapshot you can return to at any time.
###A real-world analogy
You are packing a suitcase for a trip. Your room (working directory) has clothes everywhere. You carefully choose what to pack (git add). When you zip the suitcase shut (git commit), that exact set of contents is locked in. Later you can open an old suitcase and see exactly what you packed on that day.
###The full picture (including remote)
1
2
Working Directory git add Staging Area git commit Local Repo git push Remote Repo
git pull
##Create Your First Repository
Let’s build this from scratch so you can feel every step.
1
2
mkdir my_first_repo
cd my_first_repo
Turn this folder into a Git repository:
1
git init
Expected output:
1
Initialized empty Git repository in /Users/you/my_first_repo/.git/
This creates a hidden .git folder. That folder IS your repository — all the history, all the snapshots, everything. Do not delete it.
Create a file:
1
touch README.md
Now ask Git what it sees:
1
git status
Expected output:
1
2
3
4
5
6
7
8
9
On branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
README.md
nothing added to commit but untracked files present
Git can see README.md but says “untracked”. This means: “I see this file exists, but I am not watching it yet. I will not track any changes you make to it.”
##The Four File States
Every file in your project is always in one of these states:
| State | What it means | How to move forward |
|---|---|---|
| Untracked | New file Git has never seen | git add <file> |
| Modified | Known file that has changed | git add <file> |
| Staged | Change ready to be committed | git commit -m "message" |
| Committed | Permanently saved in history | Nothing — you’re done! |
Let’s see all four states in one sequence:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#--- UNTRACKED ---
git status
#Output: Untracked files: README.md
#Move to STAGED
git add README.md
git status
#Output: Changes to be committed:
# new file: README.md
#Move to COMMITTED
git commit -m "Initial commit: add README"
git status
#Output: nothing to commit, working tree clean
#Back to MODIFIED — edit the file
echo "#My First Project" >> README.md
git status
#Output: Changes not staged for commit:
# modified: README.md
#Stage the modification
git add README.md
git status
#Output: Changes to be committed:
# modified: README.md
#Commit it
git commit -m "Add project title to README"
git status
#Output: nothing to commit, working tree clean
You just completed the core Git loop: edit stage commit. This is 80% of what you do with Git every single day.
##git status is Your Best Friend
Run git status before and after every command until the workflow is automatic. It always tells you exactly where you are and hints at what to do next.
1
git status
How to read the output:
1
2
3
4
5
6
7
8
9
10
11
12
13
On branch main which branch you are on
Your branch is up to date with 'origin/main'.
Changes to be committed: STAGED (green in terminal)
modified: index.html
Changes not staged for commit: MODIFIED but not staged (red)
modified: style.css
Untracked files: Git has never seen these
script.js
nothing to commit, working tree clean everything is committed, you are safe
##Summary
| Command | What it does |
|---|---|
git init |
Turn a folder into a Git repository |
git status |
See the current state of all files |
git add <file> |
Stage a file (move changes to staging area) |
git add . |
Stage ALL changed/new files at once |
git commit -m "message" |
Save staged changes as a permanent snapshot |
git config --global ... |
Set your name/email (once per machine) |
Next: 02-local-workflow.md — Learn to commit like a professional