Branches - Basics
What is a Branch?
A branch in Git is basically a separate line of development.
You can work on new features or fixes without touching the main codebaseThink of it as:
“I’ll create a copy of the project at this point in time and make changes there, so themainbranch stays safe.”
A typical Branch workflow looks like..
- You create a branch for a new feature or bugfix.
- You make commits only in that branch.
- You push it to GitHub.
- Later, you can merge it back into
mainthrough a Pull Request.
This ensures that experiments or changes don’t break the stable version!
Use branch naming conventions like feature/add-login, bugfix/fix-validation, or hotfix/security-patch.
This makes collaboration and tracking much clearer.
Why it’s useful
A branch is really just a safe workspace:
“I want to try something new without messing up
main.”
- Keeps
mainclean and stable. - Makes it easy to test ideas or fix issues independently.
- Supports parallel teamwork (multiple devs working on different features at the same time).
- Provides a history of changes tied to each feature or fix.
Common Branch Types
main→ always the stable production-ready code- feature branches → for new features
- bugfix branches → to solve bugs
- hotfix branches → urgent fixes on
main(sometimes merged with bugfix) - develop branch (optional) → staging ground before merging into
main
Step by Step - Guide
Prerequisites
- Git installed locally
- A GitHub Repository
- Basic Git Knowledge
#1 Creating and Switching Branches
-
Create a new branch
git branch new-feature -
Switch to it
git checkout new-feature -
Work on your code and commit changes
git add . git commit -m "Add new feature" -
Push to GitHub
git push -u origin new-feature
git checkout -b new-feature creates + switches branch
#2 Viewing and Managing Branches
- Show all branches:
$ git branch - Delete a local branch:
$ git branch -d branch-name - Delete a remote branch:
$ git push origin --delete branch-name
When working in a team, creating a branch locally does not make it visible to others.
If Person A creates a branch called feature/test-A and pushes it,
Person B won’t see it until they fetch the latest changes.
To view all branches (both local and remote), run:
git branch -a
Now what?
YOU GOT IT!
Play around with creating, switching, and deleting branches to get comfortable.
Combine this with Pull Requests and Issues to create a professional Git workflow.
Branch - Documentation
Read more about Branches at Git’s official documentation: https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell
Finished
Back to Overview: Developer Fundamentals




