Skip to content

Our new website is live! Track your progress, save lessons and learn in Kannada.

All blogs
#OpenSource#Github#Git

Contributing to Open Source: A Beginner’s Guide to Forks and Pull Requests

A comprehensive guide for beginners to contribute to the open source projects. Learn the process of forking repositories, making changes, and submitting pull requests to become an active open source contributor.

KV

K Vijay

24 Apr 2024 2 min read

Getting involved in open-source projects is a fantastic way to improve your skills, collaborate with others, and give back to the developer community. This guide walks you through the complete workflow, from forking a repository to submitting a pull request.

Step 1: Fork the Repository

To start contributing, you’ll first need your own copy of the repository:

  1. Head to the GitHub repository you want to contribute to.
  2. Click the Fork button in the top-right corner.
  3. This creates a copy of the project in your GitHub account. It’s your personal workspace.

Step 2: Clone the Fork to Your Local Machine

Now that you’ve got a fork, it’s time to work locally:

git clone https://github.com/your-username/repository-name.git
cd repository-name

Replace your-username and repository-name with your GitHub username and the repo name.


Step 3: Connect the Original Repository

To stay updated with the original project’s changes, set it as a remote:

git remote add upstream https://github.com/original-owner/repository-name.git
git remote -v

This helps you pull future updates from the source repo (often called the upstream).


Step 4: Create a New Branch

Working on a new feature or fix? Don’t do it on the main branch. Instead, create a new branch:

git checkout -b your-feature-branch

Use a branch name that describes what you're doing, like fix-navbar-bug or add-contact-form.


Step 5: Make and Save Changes

Make the necessary changes to the code using your favorite editor (like VS Code). This could be fixing bugs, adding features, or updating docs.

Once done, save your changes.


Step 6: Stage and Commit

Time to save your work locally:

git add .
git commit -m "Brief and clear message describing your changes"

Good commit messages help reviewers understand your contribution quickly.


Step 7: Push Your Branch to GitHub

Push the branch you just committed to your fork:

git push origin your-feature-branch

This will make your changes visible on GitHub.


Step 8: Open a Pull Request

With your branch pushed, head to your fork on GitHub. You’ll see a prompt to open a pull request (PR):

  1. Click Compare & pull request.
  2. Add a meaningful title and a clear description of what you've done and why.
  3. Click Create pull request.

Step 9: Collaborate and Respond to Feedback

The project maintainers will review your PR. If changes are requested:

  1. Make the edits locally.
  2. Commit and push them again to the same branch.

Your PR will automatically update, so there’s no need to create a new one.


Step 10: Wait for It to Be Merged

Once your contribution is approved, the maintainers will merge it into the original project.

Congrats! Your changes are now part of the project.


Step 11: Keep Your Fork in Sync

To keep your fork updated with the main project:

git fetch upstream
git checkout main
git merge upstream/main
git push origin main

Doing this regularly avoids conflicts when contributing again in the future.


Conclusion

You’ve just walked through the full cycle of contributing to an open-source project: forking, branching, committing, and creating a pull request. Understanding and practicing this process helps you become a valuable part of the developer community.

Keep coding and keep contributing! 🚀

Enjoyed this post?

Share it with a friend who's learning to code.