Git for EngineersBranching and Merging

Branching and Merging

Free preview

Create, switch, and merge branches like a pro.

~15 min read

Branching and Merging

Branches are Git's killer feature — they let you diverge from the main line of development and work in isolation.

Creating branches

git branch feature/login   # create
git checkout feature/login  # switch (old syntax)
git switch feature/login    # switch (modern syntax)
git checkout -b feature/login  # create + switch in one step

Merging

git checkout main
git merge feature/login

Git will create a merge commit that has two parents — combining the histories.

Fast-forward vs merge commit

  • Fast-forward: no divergence; Git just moves the pointer forward
  • 3-way merge: diverged histories; creates a new merge commit

Best practices

  1. Keep branches short-lived (hours/days, not weeks)
  2. Use descriptive names: feature/oauth-login, fix/null-pointer-auth
  3. Delete branches after merging: git branch -d feature/login