Skip to content

Forking Workflow: Contributing to Open Source Projects

DodaTech Updated 2026-06-22 6 min read

In this tutorial, you'll learn about Forking Workflow: Contributing to Open Source Projects. We cover key concepts, practical examples, and best practices.

The forking workflow lets anyone contribute to public repositories by copying the repo to your account, cloning it, making changes, and submitting a pull request.

In this tutorial, you'll learn the Git forking workflow — the standard way to contribute to open-source projects on GitHub. Forking creates a personal copy of someone else's repository where you can make changes without affecting the original. By the end, you'll fork, commit, sync, and submit pull requests like a seasoned open-source contributor.

flowchart TD
  A[Original repo: owner/project] --> B[Fork: your-username/project]
  B --> C[Clone your fork locally]
  C --> D[Add upstream remote]
  D --> E[Create feature branch]
  E --> F[Make changes & commit]
  F --> G[Push to your fork]
  G --> H[Open pull request]
  H --> I{Maintainer reviews}
  I -->|Changes requested| F
  I -->|Approved| J[Merged into original]
  J --> K[Sync your fork]

Forking a Repository

Navigate to the GitHub repository and click the "Fork" button in the top-right corner. This creates a copy under your account.

Cloning and Configuring Remotes

# Clone your fork
git clone https://github.com/your-username/project.git
cd project

# Add the original repo as "upstream"
git remote add upstream https://github.com/original-owner/project.git

# Verify remotes
git remote -v

Expected output:

origin    https://github.com/your-username/project.git (fetch)
origin    https://github.com/your-username/project.git (push)
upstream  https://github.com/original-owner/project.git (fetch)
upstream  https://github.com/original-owner/project.git (push)

Making Changes

Always work on a feature branch, not on main:

# Create a feature branch
git checkout -b fix-typo

# Make changes
echo "fixed typo" >}} README.md
git add README.md
git commit -m "Fix typo in README"

# Push to your fork
git push -u origin fix-typo

Creating a Pull Request

On GitHub, navigate to your fork. You'll see a banner: "fix-typo had recent pushes" with a "Compare & pull request" button.

  1. Click "Compare & pull request"
  2. Write a clear title and description
  3. Reference any related issues (e.g., "Closes #42")
  4. Click "Create pull request"

Syncing Your Fork

Keep your fork up to date with the original project:

# Fetch latest from upstream
git fetch upstream

# Switch to your local main
git checkout main

# Merge upstream changes
git merge upstream/main

# Push to your fork
git push origin main

Expected output:

Updating a1b2c3d..e5f6g7h
Fast-forward
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Keeping Feature Branches Updated

While working on a long-running feature branch:

git checkout feature-branch
git rebase main
# Or: git merge main

Handling Merge Conflicts in PRs

When your PR has merge conflicts, resolve them through your fork:

# Fetch upstream changes
git fetch upstream

# Switch to your feature branch
git checkout feature-branch

# Rebase on latest upstream main
git rebase upstream/main

# Resolve any conflicts, then continue
git add resolved_file.py
git rebase --continue

# Force push to update your PR
git push --force-with-lease origin feature-branch

The PR automatically updates with the resolved conflicts.

Collaboration Features for Forks

GitHub provides additional fork collaboration features:

  • Allow edits by maintainers: Check this when creating a PR so maintainers can push fixes to your branch
  • Cross-repository pull requests: PRs between forks of the same base repo work the same as within-repo PRs
  • Fork network graph: View the relationship between forks at https://github.com/owner/repo/network

Long-Term Fork Maintenance

For active contributions:

# Option 1: Keep your fork in sync with upstream
git fetch upstream
git checkout main
git rebase upstream/main
git push origin main --force-with-lease

# Option 2: Use GitHub CLI
gh repo sync your-username/project

Common Errors

Error Cause Fix
fatal: remote upstream already exists Upstream already configured git remote set-url upstream URL
Merge conflict in PR Outdated fork Rebase your branch on upstream/main
Permission denied pushing to origin Wrong remote URL Check git remote -v for your fork
PR showing extra commits Branch not based on latest upstream Rebase on upstream/main
Everything up-to-date but changes missing Wrong remote/branch Check your checkout and remote
Fork is behind by many commits Long time since sync Fetch and rebase upstream
Cannot push to upstream Only maintainers can Push to your fork, create PR
GitHub doesn't provide shell access No direct remote access Use SSH keys for authentication

Practice Questions

What is the difference between forking and cloning?

Forking creates a copy of someone else's repository under your GitHub account. Cloning downloads a repository (your fork or any other) to your local machine. Forking is a GitHub action; cloning is a Git action.

Why do I need an upstream remote?

The upstream remote points to the original repository you forked from. Without it, you cannot pull the latest changes from the original project. Your fork becomes outdated, and your pull requests will have merge conflicts.

What should I do if my fork is behind by many commits?

Fetch upstream, checkout your main branch, and rebase or merge upstream/main. Then push to your fork. For feature branches, rebase on your updated main using git rebase main. This keeps your changes on top of the latest project state.

Should I make changes on my fork's main branch?

No. Always create a feature branch for changes. Working on main makes it harder to sync with upstream and can cause conflicts when you need to create multiple pull requests simultaneously.

What if my pull request has merge conflicts?

Resolve them by fetching upstream, checking out your feature branch, and running git rebase upstream/main. Fix any conflicts, force-push to your fork: git push --force-with-lease origin feature-branch. The PR automatically updates

Challenge

Fork an open-source repository (use a test repo or a project you admire). Clone your fork, add the upstream remote, create a feature branch, make a meaningful improvement (documentation fix, code comment, or small code change), push to your fork, and open a pull request. After the PR is merged (or closed), sync your fork and clean up the feature branch locally.

Real-World Task

Find an open-source project on GitHub with a "good first issue" label. Fork the repository, set up the development environment according to its CONTRIBUTING.md, create a branch named after the issue (fix/issue-42), implement the fix, push to your fork, and submit a pull request referencing the issue. This workflow is standard practice at DodaTech — contributions from the community to tools like DodaZIP follow this exact process.


Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro