Bird
Raised Fist0
Gitdevops~20 mins

Code review in pull requests in Git - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Pull Request Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of git command showing pull request status
What is the output of the following git command when checking the status of a pull request branch locally?
Git
git fetch origin pull/42/head:pr-42
 git checkout pr-42
 git status
Afatal: 'pull/42/head' does not appear to be a git repository
B
On branch pr-42
Your branch is up to date with 'pr-42'.
nothing to commit, working tree clean
C
On branch pr-42
Your branch is based on 'origin/main', but the upstream is gone.
nothing to commit, working tree clean
D
On branch pr-42
Your branch is ahead of 'origin/pr-42' by 1 commit.
nothing to commit, working tree clean
Attempts:
2 left
💡 Hint
Fetching a pull request creates a local branch named pr-42 tracking the PR head.
🧠 Conceptual
intermediate
1:30remaining
Purpose of code review in pull requests
What is the main purpose of performing a code review in a pull request?
ATo check code quality, find bugs, and ensure standards before merging
BTo deploy the code directly to production
CTo automatically merge code changes without human intervention
DTo delete the source branch after merging
Attempts:
2 left
💡 Hint
Think about why teams review code before merging.
🔀 Workflow
advanced
2:30remaining
Correct order of steps in a pull request review workflow
Arrange the steps in the correct order for a typical pull request code review workflow.
A1,2,3,4
B1,3,2,4
C2,1,3,4
D1,2,4,3
Attempts:
2 left
💡 Hint
Think about the natural flow from coding to review to update.
Troubleshoot
advanced
2:00remaining
Error when merging pull request due to conflicts
You try to merge a pull request but get this error: "Merge conflict in file.txt". What should you do next?
ADelete the pull request and create a new one
BForce push the pull request branch to overwrite conflicts
CFetch the latest main branch, merge it locally into the PR branch, resolve conflicts, then push
DIgnore the conflict and merge using --no-verify
Attempts:
2 left
💡 Hint
Conflicts mean changes clash and need manual fixing.
Best Practice
expert
3:00remaining
Ensuring accessibility in code review comments
Which practice best ensures accessibility when leaving code review comments on UI changes?
AApprove the PR without testing UI accessibility
BOnly comment on code style and ignore UI accessibility
CRequest the developer to add more animations for better UX
DCheck color contrast, keyboard navigation, and ARIA labels in the UI code
Attempts:
2 left
💡 Hint
Accessibility means making UI usable for everyone.

Practice

(1/5)
1. What is the main purpose of a pull request in Git?
easy
A. To review and discuss code changes before merging
B. To delete a branch from the repository
C. To create a new repository
D. To reset the main branch to a previous commit

Solution

  1. Step 1: Understand what a pull request does

    A pull request is used to propose code changes and get feedback before merging.
  2. Step 2: Identify the main purpose

    It allows team members to review, discuss, and approve changes to keep code quality high.
  3. Final Answer:

    To review and discuss code changes before merging -> Option A
  4. Quick Check:

    Pull request = code review and discussion [OK]
Hint: Pull requests are for reviewing code before merging [OK]
Common Mistakes:
  • Confusing pull requests with branch deletion
  • Thinking pull requests create repositories
  • Believing pull requests reset branches
2. Which Git command is used to push a new branch to the remote repository to start a pull request?
easy
A. git push origin main
B. git merge feature-branch
C. git pull origin feature-branch
D. git push origin feature-branch

Solution

  1. Step 1: Identify the command to push a branch

    To push a new branch named 'feature-branch' to remote, use 'git push origin feature-branch'.
  2. Step 2: Understand other options

    'git push origin main' pushes the main branch, 'git pull' fetches changes, and 'git merge' combines branches locally.
  3. Final Answer:

    git push origin feature-branch -> Option D
  4. Quick Check:

    Push new branch = git push origin branch-name [OK]
Hint: Push your feature branch with git push origin branch-name [OK]
Common Mistakes:
  • Using git push origin main instead of feature branch
  • Confusing git pull with git push
  • Trying to merge before pushing the branch
3. Given this sequence of commands, what is the output of git status after step 4?
1. git checkout -b feature
2. touch newfile.txt
3. git add newfile.txt
4. git status
medium
A. On branch feature Changes to be committed: (new file: newfile.txt)
B. On branch feature nothing to commit, working tree clean
C. On branch main Changes to be committed: (new file: newfile.txt)
D. fatal: not a git repository

Solution

  1. Step 1: Analyze branch and file status

    After 'git checkout -b feature', you are on 'feature' branch. 'touch newfile.txt' creates a new file. 'git add newfile.txt' stages it.
  2. Step 2: Understand git status output

    'git status' shows staged changes. Since newfile.txt is added, it appears under 'Changes to be committed' on branch 'feature'.
  3. Final Answer:

    On branch feature Changes to be committed: (new file: newfile.txt) -> Option A
  4. Quick Check:

    Added file staged = git status shows it [OK]
Hint: Staged files show under 'Changes to be committed' in git status [OK]
Common Mistakes:
  • Assuming branch is still main
  • Thinking staging clears changes
  • Confusing untracked with staged files
4. You created a pull request but reviewers say your branch is behind main and has conflicts. What should you do to fix this?
medium
A. Delete your branch and create a new one
B. Force push your branch without updating
C. Merge main into your branch locally and resolve conflicts
D. Close the pull request and push directly to main

Solution

  1. Step 1: Understand the conflict cause

    Your branch is behind main, so changes in main conflict with your branch.
  2. Step 2: Fix conflicts by merging main

    Merge main into your branch locally using 'git merge main', resolve conflicts, then push updates to update the pull request.
  3. Final Answer:

    Merge main into your branch locally and resolve conflicts -> Option C
  4. Quick Check:

    Fix conflicts = merge main and resolve [OK]
Hint: Merge main into your branch to fix conflicts before pushing [OK]
Common Mistakes:
  • Force pushing without resolving conflicts
  • Deleting branch unnecessarily
  • Pushing directly to main ignoring review
5. You want to ensure that every pull request is reviewed by at least two team members before merging. Which GitHub feature should you configure?
hard
A. Enable auto-merge on pull requests
B. Branch protection rules with required reviews
C. Set default branch to feature branch
D. Use git stash before pushing

Solution

  1. Step 1: Identify the feature for enforcing reviews

    GitHub branch protection rules allow setting requirements like minimum number of reviewers before merging.
  2. Step 2: Understand other options

    Auto-merge merges without review, changing default branch doesn't enforce reviews, and git stash is unrelated to pull requests.
  3. Final Answer:

    Branch protection rules with required reviews -> Option B
  4. Quick Check:

    Require reviews = branch protection rules [OK]
Hint: Use branch protection rules to require reviews before merge [OK]
Common Mistakes:
  • Confusing auto-merge with review enforcement
  • Changing default branch instead of protection rules
  • Using git stash unrelated to reviews