When I first started using Git, I did everything on the main branch. It seemed easier. I would make changes, commit them, push them, and move on. For solo projects, it didn't seem like a problem.
I failed my first ever interview. I had the first round which was good, then moved on to the second round which was a home assignment. I was tasked to create a simple Django English-Swahili translator. It was simple enough. I created it, and submitted. To me I felt like I had passed.
I sought feedback as to why I failed. There were a bunch of reasons but one of them was that I only worked on the main branch.
From that experience, I decided to start working in branches for every significant and sometimes non-significant task.
What Are Branches?
A branch is an isolated version of your codebase. It allows you to work on a feature, bug fix, or experiment without affecting the main code that everyone relies on.
Think about building a login page. Instead of changing the main branch directly, you create a separate branch and do all your work there. If something breaks, only the branch is affected. The main branch remains safe.
Once the feature is complete and tested, you merge it back into the main branch.
A Typical Branch Workflow
Most development work follows a simple process.
First, make sure your local repository is up to date.
git checkout main
git pull
This ensures you're working from the latest version of the project.
Next, create a branch for your task.
git checkout -b feature-login-page
Now you're working in your own isolated environment.
Make your changes, then check what has been modified.
git status
When you're ready, stage and commit your work.
git add .
git commit -m "Add login page"
The branch still exists only on your machine at this point.
To publish it to GitHub, push it to the remote repository.
git push -u origin feature-login-page
Once the branch is online, you can open a Pull Request.
A Pull Request allows other developers to review your work before it becomes part of the main codebase.
After approval, the branch can be merged into main.
Why Use Branches?
At first, branches can feel like extra work. Creating them, switching between them, and opening Pull Requests adds a few more steps to your workflow.
The benefits outweigh that small effort. The biggest advantage is safety. If a feature breaks, the main branch remains untouched.
Users continue using a stable version of the application while you fix the issue. Branches also make teamwork much easier.
Imagine three developers working on different features at the same time. Without branches, everyone would constantly overwrite each other's changes.
With branches, each person can work independently and merge their work when it's ready.
Another benefit is cleaner code reviews. Instead of reviewing weeks of mixed changes, reviewers can focus on one feature or bug fix at a time. That makes mistakes easier to spot and feedback easier to give.
Branches and CI/CD
If you're using a CI/CD pipeline, branches become even more useful. Whenever code is pushed to a branch, automated tests can run before the code reaches production.
This helps catch problems early.Finding those issues before deployment saves a lot of headaches.
Useful Commands
As you work with branches, a few commands become part of your daily routine.
List local branches:
git branch
List local and remote branches:
git branch -a
Switch to an existing branch:
git checkout branch-name
Temporarily save uncommitted work:
git stash
Delete a local branch:
git branch -d branch-name
You don't need to memorize every Git command. These few commands are enough to handle most day-to-day branch management.
What Happens Without Branches?
Many beginners skip branching because they work alone. The problem appears when projects start growing.
A single mistake on the main branch can introduce bugs into working features.
Testing becomes harder because unfinished work gets mixed with stable code.
Eventually, you're afraid to make changes because every update feels risky.
Branches solve that problem by creating a safe space for development.
You can experiment, test ideas, and fix bugs without putting the primary codebase at risk.
Conclusion
Working in branches is one of the habits that separates small projects from professional development workflows.
It keeps your main branch stable, makes collaboration easier, and gives you the freedom to experiment without fear of breaking existing functionality.
If you're still making all your changes directly on main, try creating a branch for your next feature. Make it a habit. It will boost your productivity and make you more confident in exploring what your projects can do without fear of failure.

Top comments (0)