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.
● View the current state
○ Fetch upstream changes
○ Create a feature branch for your fix
○ Apply your fix and commit
○ Rebase your feature branch onto upstream/main
○ Push your feature branch
🧩 The HotfixUnsolved
📖 Story
Production is throwing errors. You already fixed the bug two days ago while working on a feature — the fix is buried in commit gggg2222 on feature/payments.
But feature/payments isn't ready to merge — it has half-finished work above the fix.
Cherry-pick just the fix commit onto main to unblock production, without bringing the unfinished work with it.
Goal
Solve the problem by using the correct Git commands.
Terminal
🧩 Problem: The Hotfix
Production is down. A fix exists on your feature branch — get it onto main without merging the whole branch.
Use the terminal to solve the problem. Results are checked automatically.