Skip to main content

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:

git checkout -b feature-new-login

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:

git add . git commit -m "Add login page"

Repeat this as you develop the feature.


3. Push Your Branch to GitHub

git push origin feature-new-login

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:

git checkout main git pull git branch -d feature-new-login

πŸ” Summary (Short Version)

  1. git checkout -b feature-name

  2. Make changes and commit them

  3. git push origin feature-name

  4. Open a Pull Request on GitHub

  5. Review and merge it into main

  6. Delete the branch