Dualo
Git & GitHub

Branches — parallel timelines

A branch is a named pointer to a commit. Cheap to create, cheap to delete. You branch off `main` to work on a feature, then merge back when done.

1 min read

A branch is just a name pointing at a specific commit. When you create one, you're saying 'remember this point in history — I'll add commits on a parallel line from here'.

Why branch: to work on a feature without breaking main (the stable line). You experiment freely on your branch — bad commits stay there. When ready, you merge into main.

Commands :

  • git branch <name> — create a branch (doesn't switch to it)
  • git switch <name> (or git checkout <name>) — move to a branch
  • git switch -c <name> — create AND switch in one step
  • git branch -d <name> — delete a merged branch (-D to force-delete)

Convention: name branches by intent — feature/login, fix/redirect-bug, refactor/extract-helpers. Avoid generic names like dev or mywork on shared repos.

When you commit on a branch, only that branch's pointer moves forward. The other branches are unaffected. Switching to another branch updates your working tree to that branch's content.

Practice

Type the command that creates a new branch `feature/login` AND switches to it.

Practice

Type the command to safely delete the local branch `old-feature` (refuse if commits would be lost).

Grounded on https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell

Next up

Merge vs rebase

Two ways to integrate changes from one branch into another. Merge preserves history as it happened (with a merge commit). Rebase rewrites your branch on top of another, producing a linear history.