Branching & Pull Requests
How real teams ship code together — branches, merges, conflicts, and the pull request workflow.
Branches are Git’s superpower. They let you work on a new feature or fix without touching the stable code everyone else depends on. This is how entire teams work on one project at the same time.
🎯 Learning Objectives
By the end of this lesson you will:
- Create and switch between branches
- Merge branches back together
- Understand and resolve a merge conflict
- Collaborate using pull requests on GitHub
Working with Branches
git branch # list branches
git switch -c feature-login # create + switch to a new branch
git switch main # switch back to mainThink of main as the trusted, always-working version. You build on a branch, then merge it back when it’s ready.
Merging
Once your feature works, merge it into main:
git switch main
git merge feature-loginIf no one else changed the same lines, Git merges cleanly.
Resolving a Merge Conflict
A conflict happens when two branches change the same lines. Git pauses and marks the file:
<<<<<<< HEAD
Welcome to our app!
=======
Welcome to the DevOps Hub!
>>>>>>> feature-loginEdit the file to keep what you want, remove the <<<, ===, >>> markers, then:
git add index.html
git commit -m "Resolve merge conflict in index.html"⚠ Conflicts are normal
A merge conflict is not an error or a bug — it just means Git needs a human to decide which change wins. Read both sides carefully before resolving.
The Pull Request Workflow
On a team you rarely merge straight into main. Instead:
git switch -c feature-login
# ... make changes, commit ...
git push -u origin feature-loginThen on GitHub you open a Pull Request (PR) — a request to merge your branch into main. A PR lets teammates review the code, comment, and approve before it’s merged, and it’s what usually triggers your CI/CD pipeline.
💡 You already saw a PR
The fix for this very learning hub was delivered as a pull request rather than a direct push — exactly so the changes could be reviewed before going live. That’s the workflow in action.
🧪 Hands-on Lab
Branch, Change, and Merge
- From
main, create a branchfeature-xand switch to it - Add a line to
README.mdand commit it - Switch back to
mainand mergefeature-x - Confirm the change is now on
main
🧠 Knowledge Check
Why do teams use branches?
What is a Pull Request?
💼 Interview Preparation
What's the difference between git merge and git rebase?
🎉 Section Complete
You can now branch, merge, resolve conflicts, and collaborate through pull requests — the daily workflow of every DevOps team. Next we head into the cloud with AWS.