Understanding Git Branches and Merges
This lesson explains what a branch is, how merges work, and how each merge type shapes history.
Learning outcomes
After completing this lesson, you will be able to:
- Describe commits, branches and remotes.
- Explain fast-forward and three-way merges.
- Compare merge commit, squash and rebase.
- Choose a merge type from stated requirements.
What a branch is
Git stores a project as a graph of commits. Each commit holds a snapshot of the files, the author, a message and a pointer to its parent commit. A branch is only a movable label that points to one commit, which is why creating a branch in Git is almost instantaneous. HEAD records which branch is currently checked out. When you commit, the label for the current branch moves forward to the new commit.
Git is distributed, so each clone contains the full history, and most work happens locally. A remote, usually named origin, is the shared copy on Azure Repos or GitHub. git fetch downloads new commits without changing your work, git pull fetches and integrates them, and git push sends your commits to the remote.
Git building blocks
How merging works
Merging joins two lines of work. When the target branch has not moved since a feature branch was created, Git can perform a fast-forward, moving the label forward with no new commit. When both branches have changed, Git performs a three-way merge using the two tips and their common ancestor, and creates a merge commit with two parents.
A merge conflict occurs when both branches change the same lines, and a person must decide on the result. The likelihood of conflict grows with the size of a change and the length of time a branch stays apart from main. This is the technical reason that DevOps favours small, frequent integration.
Fast-forwards, merges and conflicts
Merge types in pull requests
Azure Repos and GitHub offer the same basic choices when completing a pull request, although they name them slightly differently. Each one results in a different history on the target branch.
Merge commit
A merge commit keeps all commits from the branch and adds a commit joining the two histories. This preserves the exact development history, and the true context of each commit, but main becomes harder to read when many branches are merged. Azure Repos calls this a basic merge with no fast-forward.
Squash merge
A squash merge combines all the commits of a branch into one new commit on main. This gives a clean history with one commit per pull request, and it hides work-in-progress commits. Because the original commits are not on main, Git no longer recognizes the branch as merged, so the branch should be deleted after completion.
Rebase
A rebase replays each commit of a branch on top of main, which creates new commits with new IDs and a straight line of history. The individual commits remain visible. Azure Repos offers rebase and fast-forward, and rebase with a merge commit, which replays commits and still records a merge commit.
Rewriting commits that others have already pulled causes problems, so rebasing should be limited to branches that only you are using, unless the team has agreed otherwise. The following comparison recaps the three options.
The following diagram shows what each merge type puts on main.

Which merge type?
Choosing a merge type
A team wants a main branch with one commit per completed change, so that any change can be reverted with a single git revert. Developers want to keep committing freely on their own branches. Which merge type should the team require?
A squash merge meets both needs, as it puts one commit on main per pull request, whatever happened on the branch. A rebase would also give linear history, but it would keep every work-in-progress commit, so reverting a change could need several reverts. A merge commit keeps all branch commits, and reverting one needs the mainline parent to be specified.
Why should a branch be deleted after a squash merge?
Show answer
The branch's commits are not on main, so Git does not see it as merged. Continuing to use it causes confusing conflicts.
Exam Tips
Remember for the exam
- A branch is a movable pointer to a commit.
- A fast-forward adds no merge commit; a three-way merge creates one.
- Squash gives one commit per pull request; rebase gives linear history with all commits.
- Rebasing rewrites commit IDs, so avoid it on shared branches.
- Conflict risk grows with branch size and age.