GitHub Tutorial
- 1. Introduction to GitHub
- 2. Account Setup & SSH
- 3. Repository Management
- 4. Remotes & Syncing
- 5. Collaborating Via Branches
- 6. Forking & Pull Requests
- 7. Code Reviews & Branch Protection
- 8. Merge Strategies
- 9. Issues & Projects
- 10. Markdown & Project Wikis
- 11. Deploying to GitHub Pages
- 12. CI/CD with GitHub Actions
- 13. Packages & Releases
- 14. Gists & Discussions
- 15. Security & Dependabot
6. Forking & Pull Requests
The **Pull Request (PR)** is the absolute heart of collaboration on GitHub. It is a feature that allows a developer to notify team members that they have completed a feature and would like their changes reviewed and merged into the main project. In this chapter, we will learn about the **Forking Workflow** and how to open Pull Requests.
1. What is Forking?
A **Fork** is a copy of a repository that is created in your own personal GitHub account. Forking is commonly used in open-source development because it allows you to make changes to a project without affecting the original repository directly.

To fork a repository:
- Go to the original repository's page on GitHub.
- Click the "Fork" button in the top-right corner.
- Select your account space. GitHub will create a complete copy of the project under your profile.
2. The Forking Workflow Sequence
To contribute to a repository using a fork, follow this standard pattern:
# 1. Clone your personal fork
git clone git@github.com:your-username/original-repo.git
# 2. Add the original repository as a second remote called "upstream"
cd original-repo
git remote add upstream git@github.com:original-organization/original-repo.git
# 3. Create a feature branch
git switch -c feature/my-new-idea
# 4. Make changes, stage, and commit
git add .
git commit -m "Implement my awesome new feature"
# 5. Push changes to YOUR fork (origin)
git push -u origin feature/my-new-idea3. Opening a Pull Request
Once you push your feature branch to your fork, visit the original repository page on GitHub. GitHub will automatically detect that you recently pushed a branch and show a yellow banner:"Compare & pull request".
- Click the "Compare & pull request" button.
- Configure the branches:
- Base Repository: The original project branch you want to merge into (usually
original:main). - Head Repository: Your fork and feature branch (usually
your-username:feature/my-new-idea).
- Base Repository: The original project branch you want to merge into (usually
- Write a descriptive **Title** and **Description** explaining exactly *what* you changed and *why*.
- Click the green "Create pull request" button.
4. Draft Pull Requests
If your code is still a Work-In-Progress (WIP) but you want to share it with your team for feedback or to run continuous integration tests, you can create a **Draft Pull Request**:
- Click the drop-down arrow next to "Create pull request" and select "Create draft pull request".
- Draft PRs cannot be merged until you click **"Ready for review"**, indicating the feature is finished.
Closes #12 or Fixes #45in the PR description field. When the PR is merged, GitHub will automatically close the referenced issue for you!