0
0
Gitdevops~5 mins

Handling PR feedback and updates in Git - Commands & Configuration

Choose your learning style9 modes available
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.