Pull request workflow
Overview
A Pull Request (PR) is a request to merge your code changes into the main project. Instead of adding your code directly to the final project, you ask the team to review it first. ```python # Step 1: You make a copy (branch) of the project. main_project = ['homepage'] my_branch = main_project.copy() # Step 2: You add your new feature. my_branch.append('login_page') # Step 3: You create a PR. The team reviews it. If approved, it is merged. main_project = my_branch print(main_project) # Output: ['homepage', 'login_page'] ``` A PR acts like a security gate. It stops bad code from breaking the main project. The most important rule: **A PR is a conversation, not just a merge button.** You push your code, the team checks it, you fix any issues, and then it gets merged.
It keeps the main codebase safe. It allows the team to spot errors before they reach users.
Where used: GitHub pull requests, GitLab merge requests
Why learn this
- Every modern software team uses pull requests to manage changes.
- It is how you will submit your work in your first job.
Code walkthrough
main_branch = ['v1']
my_branch = main_branch.copy()
my_branch.append('v2')
# PR is reviewed and approved
main_branch = my_branch
print(main_branch)
Focus: main_branch = my_branch
Common mistakes
- Huge pull requests: Putting too many changes in one PR makes it impossible to review. Keep PRs small and focused on one feature.
- Ignoring feedback: A PR is a discussion. If a reviewer asks for a change, you must update your branch and reply. Do not just close it or merge anyway.
Recall questions
- Explain a pull request in your own words, as if to a classmate.
- Why is it important to create a pull request instead of adding code directly?
- What happens if the team finds an issue in your pull request?
Understanding checks
What does this print? (This simulates a PR that is NOT merged yet.)
['v1']
Because `my_work` is a copy (a branch), changes to it do not affect the main `project` until they are officially merged.
If you push 3 new commits to your branch after opening a PR, what happens to the PR?
The PR updates automatically to include the new commits.
A PR tracks the branch, not just a static set of commits. Any new commits on that branch become part of the ongoing PR.
Practice tasks
Simulate a rejected PR
Given this code that simulates a PR, modify it so that the PR is REJECTED and the main branch is not updated.