← Back to DevBytes

Git Workflows for Open Source

Git Workflows for Open Source

In open source software development, contributors from all over the world collaborate on a shared codebase. Without a structured approach to managing changes, chaos can quickly take over. A Git workflow defines the step-by-step process by which code moves from an idea to a merged commit, ensuring that projects remain organized, reviewable, and maintainable. Whether you are a first-time contributor or a seasoned maintainer, understanding these workflows is the foundation of productive open source participation.

What Is a Git Workflow?

🚀 Deploy your AI agent in 10 minutes

Managed Hermes hosting. Zero DevOps. 100M tokens/mo included.

Try it free →

A Git workflow is a branching strategy and set of conventions that dictate how developers create, review, and integrate changes into a codebase. It covers everything from naming branches to structuring commits, opening pull requests, and synchronizing with the upstream repository. In open source, the most widely adopted workflow is the fork-and-pull-request model, but variations like trunk-based development or GitHub Flow are also common. Each workflow balances the need for parallel development with the goal of a stable main branch.

Why It Matters

Adopting a consistent Git workflow benefits everyone involved:

Common Open Source Workflows

Several workflows exist, but most open source projects on platforms like GitHub, GitLab, and Bitbucket coalesce around a few proven patterns. Here are the ones you will encounter most frequently:

The Fork-and-Pull-Request Model

This is the de facto standard for public open source repositories. Contributors don’t have direct write access to the original repository. Instead, they fork it (create a personal server-side copy), push changes to their fork, and then submit a pull request to propose merging those changes back into the upstream project. This model gives maintainers full control over what enters the codebase while empowering anyone to contribute without prior permission.

GitHub Flow (Feature Branch Workflow)

Often used by teams that share write access to a single repository, GitHub Flow relies on short-lived feature branches created directly in the upstream repo. Developers branch off main, work on a feature, and open a pull request when ready. Continuous deployment projects favor this lightweight approach because it keeps the main branch constantly releasable.

Trunk-Based Development

Popular among large-scale projects like Google’s open source libraries, trunk-based development encourages developers to merge small, incremental changes directly into the main branch multiple times a day. Feature flags and comprehensive test suites ensure that incomplete work doesn’t break users. Contributors often work on very short-lived branches (sometimes just a few hours) and rely heavily on code review before pushing.

Gitflow (Less Common in Open Source)

Gitflow prescribes strict branch roles: main for releases, develop for integration, feature/, release/, and hotfix/ branches. While powerful for versioned software products, it introduces overhead that many open source projects avoid in favor of the simpler fork-and-pull-request model.

Step-by-Step Guide: Contributing with the Fork-and-Pull-Request Workflow

This section walks through a complete contribution lifecycle — from forking the repository to cleaning up after your pull request is merged. Each step includes the exact Git commands you need.

1. Fork the Original Repository

Visit the project’s GitHub page and click the Fork button. This creates a copy under your own account. Then clone your fork locally:

git clone https://github.com/YOUR_USERNAME/PROJECT.git
cd PROJECT

2. Add the Upstream Remote

To keep your fork synchronized with the original project, register the upstream repository as a remote:

git remote add upstream https://github.com/ORIGINAL_OWNER/PROJECT.git
git remote -v

The output should show origin pointing to your fork and upstream pointing to the original repository.

3. Sync Your Local Main Branch

Always start fresh by pulling the latest changes from upstream into your local main branch, then push them to your fork:

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

4. Create a Feature Branch

Never commit directly to main. Create a short, descriptive branch name that reflects your change:

git checkout -b feature/add-dark-mode
# Or, for bugfixes: git checkout -b fix/typo-in-readme

Many projects follow branch naming conventions like feature/, fix/, docs/, or chore/. Check the repository’s CONTRIBUTING.md for guidelines.

5. Make Changes and Commit

Write your code, tests, and documentation. Stage changes and commit with a meaningful message:

# Stage specific files or all changes
git add src/theme.js tests/theme.test.js
git commit -m "feat: add dark mode toggle to user settings"

Many open source projects follow the Conventional Commits format (e.g., feat:, fix:, docs:) because it enables automatic changelog generation. Keep commits small and atomic — each commit should represent one logical change.

6. Push Your Branch to Your Fork

git push origin feature/add-dark-mode

This uploads your branch to your GitHub fork. It does not affect the upstream repository.

7. Open a Pull Request

Go to your fork on GitHub. You will usually see a Compare & pull request button. Click it, verify the base repository (the upstream project) and the head repository (your fork/branch), and fill out the pull request form. A good PR description includes:

8. Respond to Code Review Feedback

Maintainers may request changes. Instead of opening a new pull request, make the adjustments on the same feature branch:

git checkout feature/add-dark-mode
# Edit files, then stage and commit
git add src/theme.js
git commit -m "fix: adjust contrast ratio for accessibility"
git push origin feature/add-dark-mode

The pull request updates automatically when you push to the branch. If you want to clean up your commit history before the final review, use interactive rebase:

git rebase -i HEAD~3   # squash, reword, or reorder the last 3 commits
git push origin feature/add-dark-mode --force-with-lease

Important: Use --force-with-lease instead of --force to avoid accidentally overwriting someone else’s work if you are collaborating on the branch.

9. Keep Your Branch Updated with Upstream

While your PR is open, the upstream main branch may receive new commits. To avoid merge conflicts, periodically rebase your feature branch onto the latest upstream main:

git fetch upstream
git checkout feature/add-dark-mode
git rebase upstream/main
# Resolve any conflicts, then:
git push origin feature/add-dark-mode --force-with-lease

Some projects prefer merging upstream main into your branch instead of rebasing. Always read the project’s contribution guidelines to know which method is expected.

10. Clean Up After Merge

Once your pull request is merged, delete the feature branch from your local machine and your fork to keep things tidy:

git checkout main
git fetch upstream
git merge upstream/main
git push origin main
git branch -d feature/add-dark-mode
git push origin --delete feature/add-dark-mode

Your fork is now clean and ready for the next contribution.

Best Practices for Open Source Git Workflows

Beyond the mechanical steps, successful contributors adopt habits that make their work shine:

Workflow Variations for Maintainers

Project maintainers often extend these workflows to manage releases and quality:

No single workflow fits every project. The key is to choose a pattern that matches the team’s size, release cadence, and community dynamics, then document it clearly.

Conclusion

Mastering Git workflows is one of the most impactful skills you can develop as an open source contributor. The fork-and-pull-request model provides a safe, scalable way to propose changes without compromising the stability of the original project. By keeping branches focused, syncing regularly, crafting meaningful commits, and respecting project conventions, you transform from a newcomer into a trusted community member. Whether you are fixing a typo, adding a feature, or maintaining a widely used library, a clear Git workflow ensures that your code travels from your editor to the main branch with clarity, collaboration, and confidence.

🚀 Need a reliable AI agent for your project?

Deploy Hermes Agent in 10 minutes. Managed hosting, zero DevOps.

Get Started — $23.99/mo
← Back to all articles