Git Pull Request Workflow Exercises
Practical exercises demonstrating Git branch integration using Pull Request methodology with rebase and conflict resolution
Introduction
The following exercises illustrate the workflow for integrating feature branches into the main branch using Git rebase and the Pull Request review process. Each exercise demonstrates collaboration between developers and reviewers, including handling merge conflicts and addressing review feedback.
Exercise 1
This exercise shows Ana and Luis working on separate feature branches, with Ana completing her integration first, followed by Luis.
Ana's Workflow
- GIT - Ana: Did commits #1 and #4 in branch ft_one
- GIT - Ana: git checkout main— Switch to the main branch
- GIT - Ana: git pull origin main— Fetch and merge the latest changes from remote main
- GIT - Ana: git checkout ft_one— Return to the feature branch
- GIT - Ana: git rebase main ft_one— Reapply ft_one commits on top of updated main
- GIT - Ana: git add <conflict_file> & git rebase --continue— Resolve conflicts and continue rebasing for each conflict
- GIT - Ana: git push origin ft_one— Push the rebased branch to remote repository
- GITHUB - Ana: She creates a new PR with base: main, compare: ft_one and specifies title and description.
- GITHUB - Reviewer: The reviewer reviews her PR changes and finds some issue with it.
- GIT - Ana: She does commit #7 to fix this issue.
- GIT - Ana: git push origin ft_one— Push the fix to update the existing PR
- GITHUB - Reviewer: The reviewer reviews the updated PR and approves it.
- GITHUB - Ana: She has integrated the changes of ft_one into main correctly.
Luis's Workflow
- GIT - Luis: Did commits #2 and #5 in branch ft_two
- GIT - Luis: git checkout main— Switch to the main branch
- GIT - Luis: git pull origin main— Sync with the latest main branch changes (includes Ana's merged code)
- GIT - Luis: git checkout ft_two— Return to the feature branch
- GIT - Luis: git rebase main ft_two— Reapply ft_two commits on top of updated main
- GIT - Luis: git add <conflict_file> & git rebase --continue— Resolve conflicts and continue rebasing for each conflict
- GIT - Luis: git push origin ft_two— Push the rebased branch to remote repository
- GITHUB - Luis: He creates a new PR with base: main, compare: ft_two and specifies title and description.
- GITHUB - Reviewer: The reviewer reviews his PR changes and approves them.
- GITHUB - Luis: He has integrated the changes of ft_two into main correctly.
Exercise 2
This exercise reverses the integration order, with Luis completing his feature branch integration first, followed by Ana.
Luis's Workflow
- GIT - Luis: Did commits #2 and #5 in branch ft_two
- GIT - Luis: git checkout main— Switch to the main branch
- GIT - Luis: git pull origin main— Fetch and merge the latest changes from remote main
- GIT - Luis: git checkout ft_two— Return to the feature branch
- GIT - Luis: git rebase main ft_two— Reapply ft_two commits on top of updated main
- GIT - Luis: git add <conflict_file> & git rebase --continue— Resolve conflicts and continue rebasing for each conflict
- GIT - Luis: git push origin ft_two— Push the rebased branch to remote repository
- GITHUB - Luis: He creates a new PR with base: main, compare: ft_two and specifies title and description.
- GITHUB - Reviewer: The reviewer reviews her PR changes and finds some issue with it.
- GIT - Luis: He does commit #7 to fix this issue.
- GIT - Luis: git push origin ft_two— Push the fix to update the existing PR
- GITHUB - Reviewer: The reviewer reviews the updated PR and approves it.
- GITHUB - Luis: He has integrated the changes of ft_two into main correctly.
Ana's Workflow
- GIT - Ana: Did commits #1 and #4 in branch ft_one
- GIT - Ana: git checkout main— Switch to the main branch
- GIT - Ana: git pull origin main— Sync with the latest main branch changes (includes Luis's merged code)
- GIT - Ana: git checkout ft_one— Return to the feature branch
- GIT - Ana: git rebase main ft_one— Reapply ft_one commits on top of updated main
- GIT - Ana: git add <conflict_file> & git rebase --continue— Resolve conflicts and continue rebasing for each conflict
- GIT - Ana: git push origin ft_one— Push the rebased branch to remote repository
- GITHUB - Ana: She creates a new PR with base: main, compare: ft_one and specifies title and description.
- GITHUB - Reviewer: The reviewer reviews her PR changes and finds some issue with it.
- GIT - Ana: She does commit #8 to fix this issue.
- GIT - Ana: git push origin ft_one— Push the fix to update the existing PR
- GITHUB - Reviewer: The reviewer reviews the updated PR and approves it.
- GITHUB - Ana: She has integrated the changes of ft_one into main correctly.
Key Workflow Patterns
Both exercises demonstrate essential patterns in collaborative Git workflows using Pull Requests:
- Rebase before PR: Developers rebase their feature branches on the latest main before creating a Pull Request to ensure linear history and identify conflicts early.
- Conflict resolution: When rebasing introduces conflicts, developers resolve them iteratively using git add and git rebase continue commands.
- Review feedback loop: After initial PR submission, reviewers may request changes, which developers address through additional commits pushed to the same branch.
- Sequential integration: When multiple developers work in parallel, the second developer must rebase on main after the first developer's changes are merged to avoid integration issues.