github-guru

๐Ÿ”„ 05 โ€“ Collaboration & Pull Requests

Welcome to the collaboration zone ๐Ÿค โ€” where developers unite, contribute, and build amazing things together.

If Git helps you track your own code, GitHub helps you collaborate on everyoneโ€™s code ๐ŸŒ.
Letโ€™s go step-by-step from forking a repo to merging pull requests โ€” just like pros in open source projects. ๐Ÿ’ช


๐Ÿด 1. Fork a Repository

A fork is your personal copy of someone elseโ€™s repo on GitHub.

Think of it like cloning your friendโ€™s notes to add your own highlights. ๐Ÿ“

๐Ÿช„ Step-by-Step:

  1. Go to the repository you want to contribute to.
  2. Click the Fork button (top-right).
  3. Choose your profile โ€” GitHub creates a personal copy.
  4. You can now experiment freely without affecting the original repo.

๐Ÿ’ก Pro Tip:
Forking is essential for open-source contributions โ€” it keeps your changes isolated and reviewable.


๐ŸŒฟ 2. Create a Feature Branch

Before you start coding, create a branch to organize your changes.
Each branch should represent one feature or bug fix.

โš™๏ธ Commands:

git checkout -b feature/add-login-page

This creates a new branch called feature/add-login-page and switches to it.

๐Ÿ’ก Branch Naming Convention:

Type Example
Feature feature/add-dark-mode
Fix fix/navbar-alignment
Docs docs/update-readme
Chore chore/dependency-updates

โœ… Keeps your repo clean and understandable for teams.


โœ๏ธ 3. Make Changes & Commit

Now, modify your code or documentation.

Once done:

git add .
git commit -m "Add login page with responsive layout"

๐Ÿ’ก Commit Tips:

๐Ÿง  Example:

โ€œFix: resolve login API error on mobile (#42)โ€


๐Ÿš€ 4. Push to Remote Branch

Once your commits are ready, push them to your forked repository:

git push origin feature/add-login-page

This uploads your feature branch to GitHub.

๐Ÿ’ก If itโ€™s your first push:

git push -u origin feature/add-login-page

Now, head to GitHub โ€” youโ€™ll see a prompt like:

โ€œCompare & pull requestโ€

Thatโ€™s your next step ๐Ÿ‘‡


๐Ÿงฉ 5. Open a Pull Request (PR)

A Pull Request (PR) is how you propose changes to a project.
Youโ€™re basically saying, โ€œHey, I made some improvements โ€” please review and merge!โ€

๐Ÿช„ Steps:

  1. Go to your forked repo on GitHub

  2. Click Compare & pull request

  3. Add:

    • A clear title: Add responsive login page

    • A short description of changes

  4. Choose:

    • Base Repository: The original project

    • Base Branch: Usually main or dev

    • Head Branch: Your feature branch

  5. Click Create Pull Request โœ…

๐ŸŽฏ Example PR title:

โ€œโœจ Add responsive login feature (mobile support)โ€


๐Ÿ‘€ 6. Review & Merge PR

Once submitted, maintainers or teammates will review your PR.

๐Ÿ’ฌ PR Review Process:

When approved:

โš™๏ธ After Merge:

Sync your local main branch:

git checkout main
git pull origin main

๐Ÿ’– 7. Contributing Guidelines for Open Source

Every big open-source repo has a CONTRIBUTING.md file that explains how to contribute effectively.

Hereโ€™s what you should include in yours ๐Ÿ‘‡

๐Ÿงฐ Example Structure:

# Contributing Guidelines

1. Fork the repository ๐Ÿด
2. Clone your fork:
   git clone https://github.com/<your-username>/<repo-name>.git
3. Create a feature branch:
   git checkout -b feature/your-feature
4. Commit your changes:
   git commit -m "Add your awesome feature"
5. Push to your fork:
   git push origin feature/your-feature
6. Submit a Pull Request ๐ŸŽ‰

๐Ÿ’ก Pro Tip: Add labels for first-time contributors like:

They attract newcomers and boost engagement ๐Ÿ’ฌ


โšก Real-World Example: Team Workflow

Hereโ€™s how a team project works in GitHub:

# Developer 1 creates feature
git checkout -b feature/add-payment

# Developer 2 fixes a bug
git checkout -b fix/api-timeout

# Both push their changes
git push origin feature/add-payment
git push origin fix/api-timeout

# Review & merge PRs into main
git checkout main
git pull origin main

Now everyone stays synced โ€” teamwork done right โœ…


๐Ÿง  Brain Hack โ€” Think of PRs Like โ€œCode Conversationsโ€


๐Ÿ’ก Best Practices for Collaboration

Habit Why It Matters
Create branches per feature Keeps history clean
Write meaningful commits Easier reviews
Sync (pull) before pushing Avoid conflicts
Respect code reviews Builds trust
Use PR templates Saves time for maintainers

๐Ÿช„ Bonus: Creating a Pull Request Template

To standardize PRs, create a file:

.github/pull_request_template.md

Example:

## ๐Ÿงฉ Description
Briefly describe the changes and motivation.

## โœ… Checklist
- [ ] Code tested
- [ ] Linting passed
- [ ] Documentation updated

## ๐Ÿ’ฌ Related Issues
Closes #issue_number

This ensures clean, consistent PRs for every contributor ๐Ÿงน


๐ŸŽฏ Quick Recap

โœ… You forked and cloned repos
โœ… You created branches for features
โœ… You pushed commits and opened PRs
โœ… You learned how reviews and merges work
โœ… You understood open-source contribution flow


๐ŸŒ Real-World Analogy

GitHub Action Real-World Example
Fork Repo Make a personal copy of a recipe ๐Ÿด
Feature Branch Add your twist to the recipe ๐Ÿง‚
Pull Request Submit your version for tasting ๐Ÿ‘จโ€๐Ÿณ
Code Review Friends give feedback ๐Ÿ’ฌ
Merge Everyone agrees โ€” add it to the cookbook ๐Ÿ“˜

๐ŸŒˆ Next Up: โ€œAdvanced Gitโ€ ๐Ÿง 

Youโ€™ll master:

rebase, stash, reset, and revert โ€” the tools pros use to rewrite and clean history like time travelers. โณ

๐Ÿ‘‰ Continue โ†’ 06-Advanced-Git


โœ๏ธ Written with ๐Ÿ’– by Mahesh Shukla โ€” building open-source confidence, one pull request at a time ๐Ÿ”„