Fork & CloneFork the upstream repository on GitHub, then clone your fork locally. The upstream is added as a second remote so you can sync with the original project.
Feature BranchNever commit directly to main. Create a descriptive feature branch for your changes. This isolates your work and makes PR review easy.
Rebase onto UpstreamWhile you work, the upstream project may move forward. Rebase your feature branch onto the latest upstream/main to keep history linear and avoid merge conflicts in the PR.
Clean PRBefore opening a PR, squash your commits into one logical change with a descriptive message. Reviewers appreciate a clean, focused commit.
📖 Story
You want to contribute a bug fix to an open source project. You've forked the repo on GitHub and cloned your fork locally.
Meanwhile, the upstream project added a new feature (via fetch). Your task is to sync with upstream, create a feature branch, make your fix, rebase onto the latest upstream, squash your commits, and push a clean branch for your PR.
This is the standard open source contribution workflow used by millions of developers on GitHub, GitLab, and Bitbucket.
View the current state
Run git log --oneline --all. Your fork's main (HEAD) has 2 commits. The upstream has 3 — it moved ahead with a version bump. You need to sync first.