Pull Requests
Even if you're the only person working on a project:
-
It helps keep your
main
branch clean and stable. -
You can review your changes before merging.
-
If others contribute, it gives you a chance to review their changes before accepting.
β Step-by-Step Guide
Letβs say someone requests a new feature for your project.
1. Create a New Branch
Instead of working on the main
branch, make a feature branch:
This creates and switches to a new branch called feature-new-login
.
Why? It keeps your main branch clean. You can work on multiple features at the same time this way.
2. Work on the Feature
Make your code changes, then commit them:
Repeat this as you develop the feature.
3. Push Your Branch to GitHub
This uploads your branch to GitHub.
4. Open a Pull Request (PR)
Go to your GitHub repo in the browser. Youβll see a "Compare & pull request" button β click it.
If not, go to the "Pull requests" tab and click "New pull request".
-
Base branch:
main
-
Compare branch:
feature-new-login
Add a title and description explaining the feature or fix.
Click "Create pull request."
Why? This opens a discussion where you (and others) can review the changes before merging.
5. Review and Test (Optional)
If you're working with a team, others can now:
-
Review your code
-
Comment or request changes
-
Approve it
If you're solo, you can still review the diff one last time before merging.
6. Merge the Pull Request
Once satisfied, click "Merge pull request".
Choose "Squash", "Merge", or "Rebase" (default is usually "Merge") β for beginners, just click "Confirm merge".
Squash = combine all commits into one.
Merge = keep all individual commits.
Rebase = advanced, cleans up history (not necessary yet).
7. Delete the Feature Branch
GitHub will give you the option to "Delete branch" after merging β click it.
Locally, also clean up with:
π Summary (Short Version)
-
git checkout -b feature-name
-
Make changes and commit them
-
git push origin feature-name
-
Open a Pull Request on GitHub
-
Review and merge it into
main
-
Delete the branch
No comments to display
No comments to display