Bird
Raised Fist0
Gitdevops~5 mins

Handling PR feedback and updates in Git - Commands & Configuration

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
Introduction
When you get feedback on your code changes in a pull request, you need to update your work and share the improvements. This process helps keep the project clean and makes sure your changes fit well with the rest of the code.
When a teammate asks you to fix or improve something in your pull request before merging.
When you find a mistake in your code after creating a pull request and want to correct it.
When you want to add more features or tests to your existing pull request based on feedback.
When you need to keep your branch up to date with the main project to avoid conflicts.
When you want to clean up your commit history before the pull request is merged.
Commands
Switch to your feature branch where you made the changes for the pull request.
Terminal
git checkout feature-branch
Expected OutputExpected
Switched to branch 'feature-branch'
Switch to the main branch to update it with the latest changes from the remote repository.
Terminal
git checkout main
Expected OutputExpected
Switched to branch 'main'
Update your local main branch with the latest changes from the remote repository to avoid conflicts.
Terminal
git pull origin main
Expected OutputExpected
From https://github.com/example/repo * branch main -> FETCH_HEAD Already up to date.
Switch back to your feature branch to merge the updated main branch.
Terminal
git checkout feature-branch
Expected OutputExpected
Switched to branch 'feature-branch'
Merge the updated main branch into your feature branch to keep your work current and resolve any conflicts early.
Terminal
git merge main
Expected OutputExpected
Already up to date.
Stage all your updated files after making changes based on the feedback.
Terminal
git add .
Expected OutputExpected
No output (command runs silently)
Create a new commit with your fixes and improvements to clearly describe what you changed.
Terminal
git commit -m "Fix issues from PR feedback"
Expected OutputExpected
[feature-branch abc1234] Fix issues from PR feedback 3 files changed, 15 insertions(+), 5 deletions(-)
-m - Add a commit message inline
Send your updated commits to the remote repository to update the pull request with your changes.
Terminal
git push origin feature-branch
Expected OutputExpected
Enumerating objects: 7, done. Counting objects: 100% (7/7), done. Delta compression using up to 4 threads Compressing objects: 100% (4/4), done. Writing objects: 100% (5/5), 1.23 KiB | 1.23 MiB/s, done. Total 5 (delta 2), reused 0 (delta 0), pack-reused 0 To https://github.com/example/repo.git 9fceb02..abc1234 feature-branch -> feature-branch
Key Concept

If you remember nothing else from this pattern, remember: always update your feature branch with feedback changes and push them to keep the pull request current.

Common Mistakes
Not switching to the feature branch before making changes.
Changes will be made on the wrong branch, causing confusion and possibly breaking the main code.
Always run 'git checkout feature-branch' to work on the correct branch.
Forgetting to pull the latest main branch before merging.
Your branch may conflict with recent changes, causing merge problems later.
Run 'git checkout main' and then 'git pull origin main' to get the latest updates before merging.
Not committing changes before pushing.
No new changes will be sent to the remote repository, so the pull request won't update.
Use 'git add' and 'git commit' to save your changes before 'git push'.
Summary
Switch to your feature branch to work on the pull request updates.
Keep your branch up to date by pulling and merging the main branch.
Stage and commit your changes clearly describing the fixes.
Push your updated branch to update the pull request with feedback.

Practice

(1/5)
1. When you receive feedback on a pull request (PR), what is the first step to update your code accordingly?
easy
A. Check out the feature branch locally to make changes
B. Merge the main branch into your feature branch without changes
C. Close the PR and create a new one
D. Delete the feature branch and start over

Solution

  1. Step 1: Switch to the feature branch

    You need to work on the branch where the PR was created to apply feedback changes.
  2. Step 2: Make the necessary code updates

    After switching, edit the code to address the feedback.
  3. Final Answer:

    Check out the feature branch locally to make changes -> Option A
  4. Quick Check:

    Update code on feature branch = A [OK]
Hint: Always update code on the feature branch first [OK]
Common Mistakes:
  • Trying to update main branch instead of feature branch
  • Closing PR unnecessarily
  • Starting a new branch without reason
2. Which git command correctly stages all changed files before committing updates for a PR?
easy
A. git commit -a -m "Update code"
B. git checkout -b update-branch
C. git push origin main
D. git add .

Solution

  1. Step 1: Stage all changes

    The command git add . stages all modified and new files in the current directory.
  2. Step 2: Commit the staged changes

    After staging, you use git commit -m "message" to save changes locally.
  3. Final Answer:

    git add . -> Option D
  4. Quick Check:

    Stage all changes = git add . [OK]
Hint: Use 'git add .' to stage all changes before commit [OK]
Common Mistakes:
  • Using git commit -a without staging new files
  • Pushing before committing
  • Creating new branches unnecessarily
3. Given the following commands run in sequence on a feature branch:
git add file.txt
git commit -m "Fix typo"
git push origin feature-branch

What happens to the existing pull request linked to feature-branch?
medium
A. A new pull request is created
B. The pull request updates automatically with the new commit
C. The pull request is closed
D. Nothing changes until you merge manually

Solution

  1. Step 1: Push updates to the feature branch

    Pushing commits to the branch linked to the PR updates the PR automatically.
  2. Step 2: PR reflects new commits

    The PR shows the new changes for reviewers to see and re-review.
  3. Final Answer:

    The pull request updates automatically with the new commit -> Option B
  4. Quick Check:

    Push to feature branch updates PR = A [OK]
Hint: Push changes to update existing PR automatically [OK]
Common Mistakes:
  • Thinking a new PR is needed for each update
  • Believing PR closes on push
  • Assuming manual merge needed to update PR
4. You tried to push updates to your feature branch but got this error:
! [rejected] feature-branch -> feature-branch (non-fast-forward)
What is the best way to fix this?
medium
A. Pull latest changes from remote and rebase before pushing
B. Delete the remote branch and push again
C. Force push with git push --force
D. Create a new branch and push there

Solution

  1. Step 1: Fetch and rebase remote changes

    Run git pull --rebase origin feature-branch to update your local branch with remote changes without merge commits.
  2. Step 2: Push the rebased branch

    After rebasing, push your changes normally with git push origin feature-branch.
  3. Final Answer:

    Pull latest changes from remote and rebase before pushing -> Option A
  4. Quick Check:

    Fix non-fast-forward by rebasing and pushing = C [OK]
Hint: Rebase remote changes before pushing to avoid errors [OK]
Common Mistakes:
  • Using force push without caution
  • Deleting remote branch unnecessarily
  • Creating new branches instead of syncing
5. You have multiple commits in your feature branch but want to combine them into one clean commit before updating the PR. Which sequence of commands achieves this?
hard
A. git merge main; git commit -m "Clean update"; git push
B. git rebase -i main; edit commits; git push
C. git reset --soft HEAD~3; git commit -m "Clean update"; git push --force
D. git checkout main; git cherry-pick feature-branch; git push

Solution

  1. Step 1: Soft reset last 3 commits

    git reset --soft HEAD~3 moves HEAD back but keeps changes staged, allowing to combine commits.
  2. Step 2: Create a single new commit and force push

    Commit staged changes with a new message, then force push to update PR with one clean commit.
  3. Final Answer:

    git reset --soft HEAD~3; git commit -m "Clean update"; git push --force -> Option C
  4. Quick Check:

    Combine commits by soft reset and force push = B [OK]
Hint: Use soft reset and force push to squash commits [OK]
Common Mistakes:
  • Using merge instead of squash
  • Forgetting to force push after rewriting history
  • Incorrectly rebasing without editing commits