What is Git and Why You Need a Workflow?
Git is a version control system. It remembers every change you make to your project forever. A workflow is the disciplined path your code follows so you never lose work, never break the main project, and can collaborate safely.
Without a workflow, Git feels confusing. With a workflow, Git feels predictable.
The Three Places Where Your Code Lives
- Working Directory β files you edit
- Staging Area β files prepared for the next snapshot
- Repository β permanent history (commits)
Edit β Stage β Commit
The Golden Rule
Never work directly on main. Always create a branch.
Understanding Branches
A branch is a safe workspace. You can experiment freely without affecting the stable project.
mainβ production-ready codefeature/*β new featuresbugfix/*β bug fixes
Before You Start: One-Time Setup
Tell Git who you are
git config --global user.name "Your Name"
git config --global user.email "you@email.com"
Clone the project
git clone https://github.com/user/project.git
cd project
The Core Idea You Must Understand First
You NEVER build features on main. Ever.
Main is sacred. It must always be stable, always working, always deployable.
All your real work happens in branches. The entire workflow exists to protect main.
The Complete Feature Workflow β Deep Explanation
Step 1 β Start from the latest main (Why this matters)
If you donβt update main first, you might build on old code. Later, when you try to merge, conflicts appear and beginners panic.
This step guarantees you start from the newest, stable version of the project.
git checkout main
git pull origin main
Step 2 β Create a branch (Your safe workspace)
This creates a copy of the project at this moment in time. You are now isolated from the stable project.
You can break things, experiment, and nothing affects anyone else.
git checkout -b feature/user-login
Step 3 β Work normally (no Git yet)
Edit files. Create new ones. Delete things. You are just programming normally.
Git does nothing until you tell it to.
Step 4 β Stage changes (telling Git what you want in the snapshot)
The staging area is where beginners get confused. Think of it as selecting which files go into the next save point.
git add .
Step 5 β Commit (create a checkpoint in history)
A commit is a permanent snapshot. You can return to it forever.
Make small commits. They tell the story of how the feature was built.
git commit -m "Create login form layout"
Step 6 β Repeat work β add β commit many times
You are building history. This is good practice, not noise.
Step 7 β Update your branch with main (very important in teams)
Other people are merging to main while you work. You must bring those changes into your branch before finishing.
git checkout main
git pull
git checkout feature/user-login
git merge main
Step 8 β Push your branch to GitHub
This is when your work leaves your computer and becomes visible to others.
git push origin feature/user-login
Step 9 β Open a Pull Request (PR)
This asks: βCan we merge my work into main?β
Review, discussion, and automated tests happen here.
Step 10 β Fix feedback
Just commit again. The PR updates automatically. No new PR needed.
Step 11 β Merge to main
Your feature is now official, stable project history.
Step 12 β Delete the branch (task finished)
git branch -d feature/user-login
Why Beginners Get Confused (and how this workflow prevents it)
- They work on
main - They donβt commit often
- They donβt pull before starting
- They donβt understand what staging does
The Mental Model
Main β Branch β Work β Add β Commit β Update β Push β PR β Merge β Delete
Video References
These videos reinforce the workflow you just learned and show it in real action.
Watching these after reading will make everything click even faster.