🥽Virtual Lab: Git Branch
This content is a draft and will not be included in production builds.

Branching, Merging and Conflicts
Section titled “Branching, Merging and Conflicts”Now that you’ve seen how add, commit, push and pull move a single line of work between the working directory, staging area, local repo and remote, it’s time for the next idea: doing more than one thing at once. Branches let you split a project’s history so you can develop a new feature, try an experiment, or apply a hotfix without disturbing the work everyone else is doing on main. Merging is how those parallel histories come back together. This is sometimes clean, sometimes not.
The lab below renders the local repository as a left-to-right commit graph, with each branch on its own horizontal “lane”. The remote panel on the right is your GitLab origin: branches only appear there once you push them. As you create branches, switch between them, commit, and merge, watch how the graph changes shape — that shape is what git log --graph is showing you on the command line.
Tasks to try
Section titled “Tasks to try”Work through these in order. After each one, glance at the What happened panel at the bottom as it explains what each command did, in plain English.
- Make a branch and switch to it. From the fresh starting state (press “reset”), type a name like
feature/logininto the branch field and clickgit branch. Notice thatHEADdoesn’t move as you’ve created a label, but you’re still onmain. Now usegit switchto move onto the new branch. - Commit on a branch. With
HEADon your feature branch, make two commits. Watch how only the feature lane grows;mainsits still on its own commit. Use “git push origin” to publish the branch to GitLab. Switch back tomainand then merge the branch into main. Notice that theHEADis now on the feature branch. If you push now you can publish this update to GItLab.
Git Branching Lab
Create branches, switch between them, and watch git merge handle fast-forwards, three-way merges, and conflicts. Push branches to GitLab so they're ready for a merge request.
The mental model: Branches are not folders or copies of the code. A branch is a movable label that points at a single commit. git branch creates a label; git switch moves HEAD to a different label; committing advances whichever label HEAD is currently riding. The graph is the truth and the labels are just convenient names for spots on it.
Now try some presets:
- Fast-forward merge. Load the Feature ready to fast-forward preset. You’re on
main(i.e., HEAD), andfeatureis two commits ahead. Rungit merge feature. Themainpointer slides forward to meetfeature— no merge commit is created, becausemainhad no commits of its own to combine. - Three-way merge. Load the Diverged branches preset. Now both branches have new commits, so a fast-forward isn’t possible. Run
git merge featurefrommainand look closely at the resulting commit: it has two parent edges feeding into it. That’s a merge commit, and it’s how Git records “these two histories came back together here”. - Resolve a conflict. Load the Merge conflict ahead preset. Both branches edited the same line of
READMEdifferently. When you rungit merge feature, the merge pauses and a red panel appears with the file showing<<<<<<<,=======and>>>>>>>markers — exactly what you’d see in a real editor. Try the Keep ours, Keep theirs and Keep both shortcut buttons to see what each does, then commit to complete the merge. - Publish a branch to GitLab. With a feature branch checked out, click
git push origin. The branch appears in the right-handoriginpanel with the prefixorigin/feature/login. In a real workflow this is the moment you’d open a merge request on GitLab. - Clean up. Once a feature branch has been merged into
main, you can safely delete the local label withgit branch -d. The commits don’t disappear — they’re still reachable frommain— but the branch pointer is gone. Try deleting an unmerged branch and read the error: Git protects you from losing work.
Knowledge Check
Section titled “Knowledge Check”Match Branching & Merging Concepts
What happens during a 'fast-forward' merge?
When does a 'three-way merge' occur?
Which markers does Git use to identify a conflict area in a file?
What is the result of deleting a local branch with 'git branch -d' after it has been merged?
© 2026 Derek Molloy, Dublin City University. All rights reserved.