This guide will take you from complete beginner to confident contributor by walking you through the entire pull request (PR) process.
Prerequisites
- A GitHub account
- Git installed on your computer
- Basic command line knowledge
Step 1: Fork the Repository
- Navigate to the repository you want to contribute to on GitHub
-
Click the "Fork" button in the top-right corner
- This creates your own copy of the repository under your GitHub account
Step 2: Clone Your Fork Locally
- Copy the URL of your forked repository (click the "Code" button)
- Open your terminal/command prompt and run:
git clone https://github.com/YOUR-USERNAME/REPOSITORY-NAME.git
cd REPOSITORY-NAME
Step 3: Set Up Upstream Remote
- Add the original repository as a remote called "upstream":
git remote add upstream https://github.com/ORIGINAL-OWNER/REPOSITORY-NAME.git
- Verify the remotes:
git remote -v
Should show both your fork (origin) and the original (upstream)
Step 4: Create a New Branch
Never work directly on the main
branch. Create a new branch for your changes:
git checkout -b your-branch-name
Good branch names describe the work: fix-typo-docs
, add-feature-x
, etc.
Step 5: Make Your Changes
- Make the necessary changes to the code/files
- Save your changes
- Stage the changes:
git add .
Or add specific files:
git add filename.ext
- Commit your changes with a meaningful message:
git commit -m "Brief description of changes"
Step 6: Push Changes to Your Fork
Push your branch to your GitHub fork:
git push origin your-branch-name
Step 7: Create the Pull Request
- Go to your fork on GitHub
- You should see a banner suggesting to create a PR - click "Compare & pull request"
- Or go to the "Pull requests" tab and click "New pull request"
-
Select the correct branches:
- Base repository: original repo's
main
(or default branch) - Head repository: your fork's
your-branch-name
- Base repository: original repo's
-
Fill in the PR details:
- Meaningful title
- Detailed description of changes
- Reference any related issues (using #issue-number)
- Click "Create pull request"
Step 8: Respond to Feedback
Project maintainers might request changes:
- Make additional commits if needed
- Push them to the same branch
- The PR will automatically update
Step 9: Sync with Upstream (if needed)
If the original repository changes while your PR is open:
git checkout main
git fetch upstream
git merge upstream/main
git checkout your-branch-name
git merge main
# Resolve any conflicts, then push
git push origin your-branch-name
Step 10: After Merge
Once your PR is merged:
- Delete your branch (both locally and on GitHub)
- Sync your fork's main branch:
git checkout main
git pull upstream main
git push origin main
Expert Tips
- Keep PRs small and focused - address one issue per PR
- Follow project conventions - coding style, commit messages, etc.
- Write good commit messages:
Summarize changes in 50 chars or less
More detailed explanation if needed. Wrap at 72 chars.
- Bullet points are okay
- Explain why, not just what
- Reference issues in your PR description (e.g., "Fixes #123")
-
Use GitHub's features:
- Markdown formatting
- Code reviews
- Suggested changes
- Consider signing commits for extra verification
Common Workflows
Forking Workflow (described above)
Best for open source contributions where you don't have write access
Branching Workflow
If you have write access to the repository, you can create branches directly in the main repo instead of forking
GitHub CLI Alternative
Advanced users can use GitHub CLI to create PRs from the command line:
gh pr create --title "Your PR title" --body "Description"
Now you're ready to contribute to projects with confidence! Start with small contributions to build your reputation in open source communities.
Top comments (0)