Lessons in this course (10)

2. Branches, switching and merging

Basic★ Must knowLesson 2 of 10

A branch is just a pointer to a commit — creating one is instant.

bash
git branch                     # list local branches
git switch -c feature/login    # create and switch (older: git checkout -b)
git switch main                # go back
git merge feature/login        # merge into the current branch
git branch -d feature/login    # delete merged branch

Fast-forward vs three-way merge:

text
Fast-forward (main has no new commits):     main ──A──B            feature: C──D
                                             result: main moves to D, no merge commit

Three-way (both moved):  main: A──B──E        feature: A──B──C──D
                         result: new merge commit M with parents E and D

git merge --no-ff feature forces a merge commit even when fast-forward is possible (keeps the feature grouped in history).