AI Hints
CI/CD with GitHub Actions · Lesson 8 of 138

Branches and Pull Requests

How teams work.

⏱ 2 min read▶ Video at 8:10🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Teams rarely commit straight to the main branch. Instead, each change is made on its own branch. When it's ready, the developer opens a pull request, asking for the branch to be merged into main. That pull request is where CI shines.

Branches and Pull Requests
From the video: Branches and Pull Requests
  • Work on a branch
  • Open a pull request
  • CI checks it

A feature branch

Git switch with dash C creates a new branch called add free shipping, and moves onto it. We make a change and commit it. The log, with all branches drawn as a graph, shows main, and our branch one commit ahead of it. On GitHub, we'd now push this branch, and open a pull request.

Terminal
git switch -c add-free-shipping
Switched to a new branch 'add-free-shipping'
echo 'FREE_SHIPPING_OVER = 50' >> app.py
git commit -qam "Add free shipping limit"
git log --oneline --graph --all --decorate
* 66c35d2 (HEAD -> add-free-shipping) Add free shipping limit
* 7418016 (main) First version of the shop

The pull request flow

Here's the flow most teams use. Create a branch, and commit your work. Push it to GitHub, and open a pull request. CI runs automatically, and shows a green tick or a red cross on the pull request. A teammate reviews the code. And when both the checks and the review are happy, the branch is merged into main.

  1. Branch
  2. Push
  3. Pull request
  4. CI checks
  5. Review
  6. Merge
The pull request flow
From the video: The pull request flow

Summary

Work happens on branches, and pull requests ask to merge them into main. CI checks every pull request before it's merged. Next, where GitHub Actions fits in.

Key takeaways
  • git switch -c
  • Pull requests
  • CI runs on every PR
Next up: Where GitHub Actions Fits — automation inside GitHub