HomebaseWorks
Lesson 1 of 4

Branches, merge, rebase and conflicts in Git

How branches work, when to merge or rebase, and a calm step-by-step way to resolve a merge conflict.

EWritten by the HomebaseWorks editorial team · reviewed 26 Oct 2026

Most Git trouble in a team happens when branches come back together. If you understand what a branch is and what merge and rebase actually do, conflicts stop being frightening and become a routine edit.

Advertisement

What a branch really is

A branch is a movable label pointing at a commit. When you commit, the label moves forward. HEAD tells Git which branch you are on. Creating a branch is cheap, so teams make one per task:

git switch main
git pull
git switch -c feature-login

Starting from an up-to-date main reduces conflicts later.

Merge or rebase

Merge joins two histories. If main has not moved since you branched, Git does a fast-forward and simply moves the label. If both sides have new commits, Git creates a merge commit with two parents. Nothing existing is rewritten.

Rebase takes your commits and replays them on top of another branch, for example git rebase main while on your feature branch. The result is a straight history, but your commits get new hashes because they are new commits.

  • Rebase your own local branch to tidy it before review.
  • Do not rebase commits that others have already pulled. Their copies will no longer match, and fixing that wastes everyone's time.
  • If unsure, merge. It is always safe for shared branches.

Resolving a conflict

A conflict means both branches changed the same lines and Git cannot choose. The file will contain markers:

<<<<<<< HEAD
timeout = 30
=======
timeout = 60
>>>>>>> feature-login

The top part is your current branch, the bottom part is the incoming branch. Resolve it in this order:

  1. Run git status to list the conflicted files.
  2. Edit each file to the correct final content and delete all three marker lines. Sometimes the answer combines both sides.
  3. Run tests or at least the program, since a file can be marker-free and still broken.
  4. Stage with git add, then run git commit for a merge or git rebase --continue for a rebase.

If things go badly wrong, git merge --abort or git rebase --abort returns you to where you started.

Common mistakes

  • Committing a file that still contains conflict markers.
  • Keeping only your own side without checking what the other change was for.
  • Working for days without pulling main, which makes conflicts larger.

Habit: pull main into your branch at least once a day, and keep each branch to one task so merges stay small.

Advertisement
Continue with Git4 lessons · 1 interview set · 1 test · 1 certificate
Not tested

More in Cloud and DevOps