Skip to content

Branching and Merging

bparlaker edited this page Oct 6, 2026 · 2 revisions

Branching and Merging

Why branch?

A branch lets you work on a feature, fix, or experiment in isolation - main stays stable while you try things.

git switch -c feature/issue-labels     # create and switch
git branch                             # list local branches (* = current)
git branch -a                          # include remote branches

Typical feature-branch workflow

git switch main && git pull
git switch -c docs/undoing-changes
# edit files...
git add .
git commit -m "docs: add Undoing Changes page (#4)"
git push -u origin docs/undoing-changes
# open a Pull Request on GitHub, get review, merge

Fast-forward vs. merge commit

Fast-forward - main has not moved, so Git just slides the pointer:

before:  A---B (main)            after:  A---B---C---D (main, feature)
              \
               C---D (feature)

Three-way merge - both branches moved, Git creates a merge commit M:

A---B---E (main)          A---B---E-------M (main)
     \              →          \         /
      C---D (feature)           C-------D
git merge feature            # fast-forward if possible
git merge --no-ff feature    # always create a merge commit (keeps the "this was a feature" bubble)
git merge --squash feature   # squash all changes into one new commit

Resolving a merge conflict

git merge feature
# CONFLICT (content): Merge conflict in README.md

Git marks the file:

<<<<<<< HEAD
Hi! I'm Berker.
=======
Hello, my name is Berker Parlaker.
>>>>>>> feature
  1. Edit the file to the final version and delete the markers.
  2. git add README.md
  3. git commit (or git merge --continue)

Tip: git config --global merge.conflictStyle zdiff3 also shows the common ancestor, which makes conflicts much easier to understand.

Branch naming conventions used here

Prefix Use
feature/ new functionality
fix/ bug fixes
docs/ README / wiki / documentation
chore/ repo maintenance

Include the issue number: docs/4-undoing-changes.

Clone this wiki locally