Git for Beginners: Basics and Essential Commands
Imagine five developers working on the same project. No Git. Just folders named final_v2_FINAL_new.zip flying over email.
Someone overwrites someone else's work. Nobody knows what changed. Chaos.
Git fixed this. It tracks every change, by every person, forever.
Core Concepts
- Repository — Your project's folder, tracked by Git
- Commit — A snapshot of your code at a moment in time
- Branch — A parallel version of your code
- HEAD — Where you currently are in the history
Essential Commands (With Outputs)
Initialize a Repository
Turn any folder into a Git-tracked project:
git init
Output:
Initialized empty Git repository in /Users/you/my-project/.git/
Check Status
See what's changed since your last commit:
git status
Output (untracked files):
On branch main
Untracked files:
(use "git add <file>..." to include in what will be committed)
index.html
style.css
nothing added to commit but untracked files present
Stage Files
Tell Git which files to include in the next snapshot:
git add index.html # Stage one file
git add . # Stage everything
Now check status again:
git status
Output (staged files):
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: index.html
new file: style.css
Commit Changes
Save a snapshot with a message:
git commit -m "Add homepage and styles"
Output:
[main 3a4b5c6] Add homepage and styles
2 files changed, 45 insertions(+)
create mode 100644 index.html
create mode 100644 style.css
View History
See all commits:
git log --oneline
Output:
3a4b5c6 Add homepage and styles
1d2e3f4 Initial commit
Create a Branch
Work on features without touching main code:
git branch feature-navbar
git checkout feature-navbar
Or do both in one command:
git checkout -b feature-navbar
Output:
Switched to a new branch 'feature-navbar'
Merge Branches
Done with your feature? Merge it back:
git checkout main
git merge feature-navbar
Output:
Updating 3a4b5c6..7d8e9f0
Fast-forward
navbar.html | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
The Workflow
git init # Once per project
git status # Check what changed
git add . # Stage changes
git commit -m "" # Save snapshot
git log # View history
Initialize → Make changes → Stage → Commit → Repeat.
That's it. Every professional developer follows this loop daily.
Git isn't just a tool. It's your safety net. Learn it once, use it forever.