0
0
Gitdevops~5 mins

Pull request process in Git - Commands & Configuration

Choose your learning style9 modes available
Introduction
When multiple people work on the same code, changes need to be reviewed before joining the main project. The pull request process helps teams review, discuss, and approve code changes safely before adding them to the main codebase.
When you finish a new feature and want your team to review it before adding it to the main project.
When you fix a bug and want to make sure the fix is correct and does not break anything.
When you want to ask for feedback on your code changes from teammates.
When you want to keep the main project stable by reviewing all changes before merging.
When you want to track the history and discussion of a specific change in the project.
Commands
Create and switch to a new branch named 'feature-login' to work on a new feature without affecting the main code.
Terminal
git checkout -b feature-login
Expected OutputExpected
Switched to a new branch 'feature-login'
Stage all changed files to prepare them for committing.
Terminal
git add .
Expected OutputExpected
No output (command runs silently)
Save the staged changes with a clear message describing the new login feature.
Terminal
git commit -m "Add login feature with validation"
Expected OutputExpected
[feature-login abc1234] Add login feature with validation 3 files changed, 45 insertions(+), 2 deletions(-)
-m - Add a commit message inline
Upload the 'feature-login' branch to the remote repository so others can see and review your changes.
Terminal
git push origin feature-login
Expected OutputExpected
Enumerating objects: 10, done. Counting objects: 100% (10/10), done. Delta compression using up to 4 threads Compressing objects: 100% (7/7), done. Writing objects: 100% (7/7), 1.23 KiB | 1.23 MiB/s, done. Total 7 (delta 3), reused 0 (delta 0), pack-reused 0 remote: remote: Create a pull request for 'feature-login' on GitHub by visiting: remote: https://github.com/example/repo/pull/new/feature-login remote: To https://github.com/example/repo.git * [new branch] feature-login -> feature-login
Switch back to the main branch to prepare for merging the approved changes.
Terminal
git checkout main
Expected OutputExpected
Switched to branch 'main' Your branch is up to date with 'origin/main'.
Update your local main branch with the latest changes from the remote repository to avoid conflicts.
Terminal
git pull origin main
Expected OutputExpected
Already up to date.
Merge the reviewed feature branch into the main branch to include the new login feature.
Terminal
git merge feature-login
Expected OutputExpected
Updating abc1234..def5678 Fast-forward login.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
Push the updated main branch with the new feature to the remote repository so everyone can use it.
Terminal
git push origin main
Expected OutputExpected
Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 350 bytes | 350.00 KiB/s, done. Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 To https://github.com/example/repo.git abc1234..def5678 main -> main
Key Concept

If you remember nothing else from this pattern, remember: use a separate branch for your changes, push it, create a pull request for review, then merge only after approval.

Common Mistakes
Committing changes directly to the main branch without using a feature branch.
This can cause unstable code in the main project and makes it hard to review or undo changes.
Always create a new branch for your work before making changes.
Not pulling the latest changes from main before merging your feature branch.
This can cause merge conflicts or overwrite others' work.
Run 'git pull origin main' to update your local main branch before merging.
Pushing changes without a clear commit message.
It makes it hard for others to understand what your changes do during review.
Write clear, descriptive commit messages explaining your changes.
Summary
Create a new branch to work on your feature or fix.
Commit and push your changes to the remote repository.
Open a pull request for your team to review the changes.
After approval, merge the feature branch into the main branch.
Keep your main branch updated by pulling latest changes before merging.