IICTPIICTP

Blog / Guides

Answers3 November 20264 min read

What is a Git branch, and how should a team use branches?

A Git branch is a movable pointer to a line of commits. It lets you work on a change in isolation without disturbing the main line of code, then merge it back when it is ready. Branches are cheap in Git, so teams use them for almost every change.

In this post
  1. Why use a branch at all?
  2. What does a simple workflow look like?
  3. What is the difference between merge and rebase?
  4. What are merge conflicts?
  5. How long should a branch live?
  6. Sources and further reading

Why use a branch at all?

Without branches everyone edits the same line of history, and one person’s half-finished work can break everyone else. A branch gives each change its own space, so it can be built, tested and reviewed before it reaches the shared code.

What does a simple workflow look like?

  1. Update your local copy of the main branch.
  2. Create a branch named for the change, for example a short description of the fix.
  3. Commit small, meaningful steps with clear messages.
  4. Push the branch and open a pull request.
  5. After review and passing checks, merge it and delete the branch.

What is the difference between merge and rebase?

A merge joins two lines of history and keeps a record of when they diverged. A rebase replays your commits on top of the latest main branch, giving a straight history. Both are valid. The usual rule is not to rebase commits that other people have already pulled.

What are merge conflicts?

A conflict happens when two branches changed the same lines and Git cannot decide which version to keep. You resolve it by editing the file, choosing or combining the changes, and committing the result. Short-lived branches that are merged often produce far fewer conflicts.

How long should a branch live?

As short as practical, ideally hours or a few days. Long-lived branches drift away from the main line and make merging painful, which is why many teams prefer small changes that merge frequently. Trunk-based development takes that idea furthest.

Sources and further reading

  1. Chacon, S. and Straub, B. Pro Git (2nd ed.), chapter 3, “Git Branching”. git-scm.com/book.

Go deeper: CTP™ credential · the TPBOK™ standard · Check your experience

IICTP is an independent technical credentialing body.

Keep reading

← All posts

New guides in your inbox

Plain-language guides on technical practice, now and then. You confirm your address first, and you can unsubscribe at any time.

Where do you stand?

Find the credential that fits the work you do.