STEP 05 OF 13
×Branching: Working in Parallel
A branch is an independent line of development. Branching lets you experiment or build a feature without affecting the stable, working version of your project.
Why branch at all
The main branch usually holds the stable, deployable version of a project. Creating a separate branch for new work means mistakes and half-finished features never disturb that stable line.
Creating and switching
You can create a new branch and move onto it in a single command. Once on a branch, every commit you make stays isolated there until you decide to merge it elsewhere.
Naming branches well
Descriptive branch names like feature/user-auth or fix/header-bug make it instantly clear what each branch is for, especially on a team.
>_ COMMANDS YOU'LL USE
git branchList all branches in the repositorygit branch feature/loginCreate a new branch without switching to itgit checkout feature/loginSwitch to an existing branchgit checkout -b feature/loginCreate a branch and switch to it in one stepgit switch feature/loginModern alternative to checkout for switching branches💡Treat the main branch as sacred. Almost all new work should happen on a separate branch first.
⚠️Common mistake: Working directly on main