Branch
You might say
I need to try a different approach, but I don't want to break the version that works now.
Develop an independent line of work without changing the main lineA branch is a movable name pointing to a series of commits. It lets a feature, fix, or experiment proceed separately and later be merged. Create branches from the right starting point and keep their purpose small enough to review.
Know first
When to use it
- Build a feature separately
- Fix a bug without disturbing ongoing work
- Try an experiment
- Prepare a release or urgent patch
When NOT to use it
- Use one long-lived branch for unrelated work
- Create it from an outdated or wrong starting point
- Keep finished branches forever without a reason
- Assume switching branches saves uncommitted changes safely
Anatomy
main
feature/new-nav
HEAD → You are now in feature/new-nav
Default branches usually contain verified changes; whether direct commits are allowed depends on team rules
A new branch is created from a certain commit, and the starting point corresponds to the snapshot at that time
Can be named according to feature/function name for independent development and testing
HEAD points to the currently checked-out branch or commit, and git switch will update its point.
Variants
switch -c
git switch -c feature/new-nav
Create and switch to a new branch from the current commit
switch
git switch main
Switch the working directory to the file version of main
branch
git branch
View local branch list
branch -d
git branch -d feature/new-nav
After confirming that the branch has been merged or is no longer needed
Typical use cases
Feature branch
$ git switch -c feature/new-nav
Switched to a new branch 'feature/new-nav'
Create and switch to a new branch from the current commit
Bug-fix branch
Experiment
Release branch
Further reading