Chapter

Branching and merging

Work on features in isolation with branches, then combine them: create and switch branches, merge, resolve conflicts, and clean up.

Git Basics 5 Lessons from courses

About this chapter

In this chapter you'll learn what a branch really is, how to create and switch between branches, how to merge one branch back into another, what a merge conflict is and how to resolve it calmly, and how to delete branches once you're done. This is the part of Git that lets you build a feature without disturbing your working code.

Lessons from courses

  1. 1 What is a branch? What a Git branch really is: a lightweight, movable pointer to one commit. Understand HEAD, why main is just a branch, and why branches cost almost nothing.
  2. 2 Creating and switching branches Create a branch with git branch, move onto it with git switch, do both at once with git switch -c, and list your branches. Plus how git checkout fits in.
  3. 3 Merging branches How git merge works: bring a feature branch into main, tell a fast-forward apart from a merge commit, and check the result with git log --oneline.
  4. 4 Resolving merge conflicts Resolve a Git merge conflict: read the conflict markers, edit the file, then git add and git commit to finish - or git merge --abort to back out safely.
  5. 5 Deleting branches Delete a Git branch safely with git branch -d, force-delete an unmerged branch with -D, and see why clearing out merged branches keeps your repo tidy.
Git Basics Go to course