← Back to Home
🌿

Branching & Pull Requests

How real teams ship code together — branches, merges, conflicts, and the pull request workflow.

13 min read📚DevOps Fundamentals

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:


Working with Branches

bash
git branch                     # list branches
git switch -c feature-login    # create + switch to a new branch
git switch main                # switch back to main
bash — 80×24
student@devops:~$git switch -c feature-login

Think 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:

bash
git switch main
git merge feature-login

If 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:

text
<<<<<<< HEAD
Welcome to our app!
=======
Welcome to the DevOps Hub!
>>>>>>> feature-login

Edit the file to keep what you want, remove the <<<, ===, >>> markers, then:

bash
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:

text
git switch -c feature-login
# ... make changes, commit ...
git push -u origin feature-login

Then 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

  1. From main, create a branch feature-x and switch to it
  2. Add a line to README.md and commit it
  3. Switch back to main and merge feature-x
  4. Confirm the change is now on main

🧠 Knowledge Check

Knowledge Check

Why do teams use branches?

Knowledge Check

What is a Pull Request?


💼 Interview Preparation

Interview Q&A

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.

Up Next

Introduction to Python for DevOps

You've mastered this lesson. Continue your journey to becoming a DevOps Engineer.

Start Next Lesson