Branches and Switching

View saved

Understand a branch

A branch is a movable label pointing at a commit. The default branch is often named main. New work usually belongs on a short-lived feature branch.

List and create branches

Create a branch for a change, then switch to it before editing files.

git branch
git branch feature/add-about-page
git switch feature/add-about-page

Create and switch in one step

Most everyday work uses this shorter form.

git switch -c feature/fix-typo

Move between branches

Commit or stash your work before switching if Git warns that local changes would be overwritten. Check where you are with status.

git switch main
git switch feature/fix-typo
git status

Comments

One comment per signed-in account. Comments are saved with this page’s URL.