Stay in Sync: Open Source Git Workflow Guide

September 11, 2024 (1y ago)

Aloy Sathekge

My workflow for contributing to open source projects

Contributing to open source projects can feel intimidating at first. But once you understand the workflow, it becomes a seamless and rewarding process. This guide will walk you through a clean and efficient workflow that helps you stay in sync with the project while keeping your contributions organized.

Setup: Fork and Clone

Start by forking the repository on GitHub. Then, clone your fork and link it to the original repo:

git clone git@github.com:yourusername/project.git
cd project
git remote add upstreamtps://github.com/original-owner/project.git

Syncing with the Original Project

Before creating a feature, always sync your local main branch:

git checkout main
git pull upstream main
git push origin main

Creating a New Feature Branch

Create a new branch for your work:

git checkout -b feature/your-task-name

Use clear, descriptive names like feature/login-form, fix/button-color, or docs/api-reference.

Commit Your Work

As you make progress, commit your changes with specific messages:

git add .
git commit -m "Add login form with validation"

Sync and Rebase Often

To keep your branch up to date:

git checkout main
git pull upstream main
git checkout feature/your-task-name
git rebase main

If there are conflicts:

# Edit conflicting files
git add .
git rebase --continue

Push and Create a Pull Request

Once your feature is ready:

git push origin feature/your-task-name

Then open a pull request (PR) on GitHub with the following format:

## What
Brief description of the changes
 
## Why
Explain the problem you're solving
 
## How to Test
Steps for verifying the changes

Pro Tips

  • Branch Naming: Use feature/, fix/, or docs/ prefixes
  • Never commit directly to main

Daily Flow

git checkout main
git pull upstream main
git push origin main
git checkout -b feature/task
# Code, commit, push, PR

Final Thoughts

Open Source is the way, go contribute.