The fork-and-PR pattern
Most platforms expect this flow: fork the upstream repo, clone your fork, branch for the change, push, open a pull request. Git treats it as a triangular workflow with two remotes.
Setup
git clone [email protected]:you/project.git
cd project
git remote add upstream https://github.com/org/project.git
git fetch upstream
git checkout -b fix/typo upstream/main
Branching off upstream/main rather than origin/main ensures you start from the canonical tip, not your possibly-stale fork.
Keeping up to date
git fetch upstream
git rebase upstream/main
git push --force-with-lease origin fix/typo
--force-with-lease refuses to overwrite remote work you have not seen, a safer alternative to --force.
Crafting commits
Open-source projects expect clean history. Use small, well-described commits with imperative-mood subjects under 72 chars and bodies explaining "why." Sign off with DCO when required:
git commit -s -m "fix(parser): handle empty input
Reject empty buffer with InvalidInput rather than panicking. Adds a
regression test in tests/parser/empty.rs.
Closes #1234"
Mailing-list projects
For projects like Linux, use git format-patch and git send-email. See "Maintaining a patch series with git format-patch".
Reviewing feedback
Use fixup commits and autosquash:
git commit --fixup=<sha>
git rebase -i --autosquash upstream/main
git push --force-with-lease
Pair with git range-diff to show reviewers what changed since the last revision. See "Git range-diff: comparing revision series".
Sign-off and trailers
git config --global format.signOff true
git commit --amend --no-edit --trailer 'Reviewed-by: Alice <a@x>'
git interpret-trailers --in-place --trailer 'Cc: maintainers@list' COMMIT_MSG
Common mistakes
Branching off your fork's main when it is months behind; always sync from upstream first. Force-pushing without --force-with-lease; you can clobber a reviewer's edits. Mixing unrelated changes in one PR — split via git rebase -i with edit verbs. Forgetting the project's CONTRIBUTING.md style guide.
Related
See "Multiple remote workflows", "Interactive rebase mastery", and "GPG signing commits and tags".