Pull request workflow

RoadmapsPython

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

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

Recall questions

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.

Return to Python Roadmap