Branch
In one line
A branch is an independent line of development that lets you work on changes without affecting the main history.
In simple words
A branch is a separate timeline of commits. When you create a branch, you can make commits on it without touching the main line (usually called main or master). This lets you develop a feature or fix a bug in isolation, then merge it back when ready.
Branches are cheap and fast in Git — creating one is just a pointer move. A common workflow is to create a feature/login branch, build the feature, then open a pull request to merge it into main. If the feature is rejected, you simply discard the branch.
The branch you are currently on is called the "current" or "checked out" branch. Switch branches with git checkout or git switch. List all branches with git branch, and create a new one with git branch <name> or git checkout -b <name>.
Example
# Create and switch to a new branch
git checkout -b feature/login
# Make some commits on the branch...
git add .
git commit -m "Add login form"
# Switch back to main
git checkout main
# List all branches
git branchgit checkout -b creates and switches to a new branch. Commits on it do not affect main until you merge.
Common confusions
Confused with: fork
The difference: A branch is a line of development within a single repository; a fork is a complete copy of a repository under your own account. Branches are lightweight and local; forks are server-side and used for contributing to others' projects.
Related terms
Related Resources
Related Lessons
- Git Status
See which branch you are on
Related Projects
- Branch Workflow Simulation
Practice branching and merging
Learn the fundamentals
Deepen your understanding with structured lessons on this topic.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.