GitHub Contributing
Read a contributing guide, fork or branch correctly, keep a small diff, and respond to review without rewriting shared history.
The guide is Git; the path is GitHub
GitHub Collaboration gave issues and pull requests a repeatable shape. This lesson is the outsider path: read the project's contributing guide, then send a change the maintainers can review. GitHub Fork already named origin and upstream. GitHub Pull Requests already opened a same-repo pull request. Here you choose the correct path and keep the diff small.
The files and the branch
CONTRIBUTING.md is an ordinary path. git add stages it. The feature branch is a Git pointer. Follow-up commits are Git objects.
Fork, pull request, and review
Fork copies the hosted repository into your namespace. The pull request compares your head with their default branch. Review comments stay on GitHub.
# These are Git. None of them is a GitHub contribution.
git add README.md
git commit -m "Note"
git push origin mainUse a disposable GitHub repository you own for the files and the write-access walkthrough. Write the fork commands; do not fire them at a popular project's Issues tab as homework.
Read before you write
Before you touch files on a project you do not maintain, read what that project already published. GitHub shows a contributing banner when CONTRIBUTING.md or .github/CONTRIBUTING.md exists. That banner is GitHub. The file is Git.
# Contributing
This repository accepts small, issue-linked changes.
## Before you write code
1. Read this file and the issue / pull request templates.
2. Search existing issues. Open one if the problem is not listed.
3. Wait for a maintainer to confirm the work is wanted, unless the issue already invites a pull request.
## How to send a change
- If you have write access: branch from the default branch. Do not commit on `main`.
- If you do not: fork on GitHub, clone your fork, add `upstream`, fetch, then branch from `upstream/main`.
- Keep one concern per pull request. Do not mix docs, refactors, and features.
- Open a pull request against the original default branch. Fill the pull request template. Link `Closes #N`.
- After review: commit the fix on the same branch and `git push`. Do not force-push once review has started.
## What we will not merge
- Drive-by reformatting of files you did not otherwise change
- Secrets, tokens, or generated files
- Changes that skip the issue when this file asked for one
# From a clone of a GitHub repository YOU own
git switch main
git pull origin main
git switch -c feature/contrib-guide
# Write CONTRIBUTING.md at the repository root, then:
git add CONTRIBUTING.md
git diff --cached
git commit -m "Add a contributing guide for small issue-linked changes"
git push -u origin feature/contrib-guideTest what you learned
Type the Git command that stages CONTRIBUTING.md at the repository root.
CONTRIBUTING.md
How to send a change: issue first or not, fork or branch, small diffs, how to answer review.
Templates
Issue and pull request templates from Collaboration still apply. Fill them. Do not paste a screenshot of git status instead of a reproduction.
Code of conduct
If CODE_OF_CONDUCT.md exists, it is a Git file about behavior, not a Git command. Read it. Do not debate it in the pull request.
DCO or CLA
If the guide asks for a Developer Certificate of Origin, git commit -s adds a Git sign-off trailer. A GitHub CLA bot is GitHub. Follow the file; do not invent a signing lesson here.
Search existing issues. Open a complete issue when the guide requires one. GitHub Issues already required problem, expected result, and reproduction. A surprise pull request that skips that contract is why maintainers close drive-by work.
Fork or write-access branch
The contributing guide, not habit, chooses the path. Git does not know whether you are a collaborator. GitHub permissions do.
Write access
Clone the original as origin. git switch -c feature/contrib-note. Push that branch. Open a pull request in the same repository. Do not commit on main.
No write access
Fork on GitHub. Clone your fork. origin is you; upstream is them. Fetch, catch up, then branch from current upstream/main.
Never the default branch
git push upstream main aims at someone else's shared history. Permission denied is the correct answer. Do not force-push to “fix” it.
This lab
Add the guide and walk the write-access path on a repository you own. Keep the fork-path commands written down so you can run them when you lack write access for real.
# You already have write access. CONTRIBUTING.md said: branch, do not commit on main.
git switch main
git pull origin main
git switch -c feature/contrib-note
# Make ONE small change the issue asked for, then:
git add README.md
git diff --cached
git commit -m "Note how outsiders should read CONTRIBUTING.md"
git push -u origin feature/contrib-note
gh pr create --base main --title "Note the contributing guide in README" --body "$(cat <<'EOF'
## Summary
Points README at CONTRIBUTING.md so a stranger knows how to send a change.
## Linked issue
Closes #1
## How to verify
1. Open README.md on this branch.
2. Confirm it links CONTRIBUTING.md.
3. Confirm no other files changed.
EOF
)"Test what you learned
Type the Git command that creates and switches to feature/contrib-note.
GitHub cannot fork a repository into the same account that already owns it. That is why this workshop does not pretend you forked your own practice repo. The fork commands below are the real outsider path; they use ORIGINAL/REPO and YOU as placeholders, the same way GitHub Fork did.
Keep a small diff
A contribution is one concern. Maintainers review the patch, not your formatter. Before you open the pull request, inspect the range the review will see.
One issue
The branch exists because of one GitHub issue. Closes #N names it. A second concern is a second branch.
Inspect the range
git diff main...HEAD --stat should list only the files that issue required. Extra files are extra review.
Not a rewrite
Do not re-indent a file you did not change. Do not upgrade every dependency as a “drive-by.”
Not a dump
Do not include editor swap files, node_modules, or tokens. Git .gitignore still applies.
Open the pull request against the original
Same-repo pull requests used gh pr create --base main in GitHub Pull Requests. A fork-based contribution must name the original repository, or GitHub will open the conversation on your fork—where the maintainers are not watching.
# You do NOT have write access. Fork first (GitHub), then clone YOUR copy.
# origin = your fork. upstream = ORIGINAL/REPO. See GitHub Fork.
git switch main
git fetch upstream
git merge upstream/main
git push origin main
git switch -c feature/contrib-note
# Small change, commit, then:
git push -u origin feature/contrib-note
gh pr create --repo ORIGINAL/REPO --base main --head YOU:feature/contrib-note --title "Note the contributing guide in README" --body "$(cat <<'EOF'
## Summary
Points README at CONTRIBUTING.md so a stranger knows how to send a change.
## Linked issue
Closes #1
## How to verify
1. Open README.md on this branch.
2. Confirm it links CONTRIBUTING.md.
3. Confirm no other files changed.
EOF
)"Test what you learned
Type the GitHub CLI command that opens a pull request on ORIGINAL/REPO (the flags come after).
--head YOU:feature/contrib-note is GitHub's name for “the branch on this user's fork.” Git still pushed that branch to origin. GitHub stores the comparison. After it merges, fetch and update your fork's default branch the way the Fork lesson taught—do not push the original main.
Respond without rewriting shared history
GitHub Code Review already required this habit. It is the same habit when you are the outsider: requested changes are answered on the same feature branch with an ordinary push.
# Stay on feature/contrib-note. Review already started.
# Edit the same files the review named, then:
git add README.md
git diff --cached
git commit -m "Use the path the review asked for"
git push
# These rewrite history reviewers already read. Do not run them on a shared pull request:
# git push --force
# git push --force-with-leaseSame branch
Do not open a second pull request for the fix. The conversation already points at this head.
Ordinary push
git push adds a commit reviewers can diff against the comment they left.
No force-push
Once review has started, rewriting that branch hides the commits people already read. Save --force-with-lease for private cleanup before the first review, if the guide allows it.
Then stop
Do not merge the original default branch unless you are a maintainer. After merge, sync your fork. Delete the feature branch.
What not to invent
Practice PRs on famous repos
Do not open a “typo” pull request on a popular project as this course's homework. Maintainers are not a lab.
CONTRIBUTING.md on a stranger's default branch
Your practice guide belongs on a repository you own. Adding process files to someone else's project is not a first contribution unless they asked.
Actions as a contribution
A workflow file is GitHub Actions. Do not drop .github/workflows into a project whose guide never asked for it.
Tokens in the diff
Do not paste a personal access token into a pull request to “prove auth.” Authentication already taught secret hygiene.
Guided practice: guide, then one change
- 01Pick a repository you own
Confirm
git remote -vis your GitHub URL. Update localmain. - 02Add the guide
On
feature/contrib-guide, addCONTRIBUTING.mdwith the two paths (write access versus fork), a small-diff rule, and “no force-push after review.” Open a pull request and merge it. - 03Open one issue
File a complete issue: problem, expected result, reproduction. The work is a one-line README pointer to
CONTRIBUTING.md. - 04Send the write-access change
git switch -c feature/contrib-note. Make that one README change. Push. Open a pull request withCloses #N. - 05Request a change, then answer it
Leave a review that asks for a clearer sentence. Fix it on the same branch.
git pushwithout force. Then merge if you are done. - 06Write the fork path
On paper or in the lab notes, record
gh pr create --repo ORIGINAL/REPOwith--head YOU:feature/contrib-note. Do not run it against a project you do not maintain.
Independent lab: contributing path
- On a GitHub repository you own, add
CONTRIBUTING.mdthat names both paths (write-access branch versus fork), requires a small issue-linked diff, and forbids force-push once review has started. Land it through a short-lived pull request. - Open one complete GitHub issue. On
feature/contrib-note, make a single matching change. Open a pull request that fills the template and includesCloses #N. - Request one change on that pull request. Answer with a new commit and
git push. Do not usegit push --force. - Write the fork-based command you would run without write access, including
gh pr create --repo ORIGINAL/REPO. Do not open that pull request on a popular public project. - Write six lines: repository URL, issue number, pull request number, whether this walkthrough used write access or a fork, one sentence that distinguishes
CONTRIBUTING.mdfrom a GitHub label, and one sentence that distinguishesgit pushafter review fromgit push --force.
Common contributing mistakes
Skipping the guide
If the file asked for an issue first, a surprise pull request is incomplete work, not speed.
Calling clone a contribution
Clone is Git. Fork is GitHub. A pull request against the original is the contribution.
A giant unrelated diff
Format-the-world patches get closed. One concern per branch.
Force-pushing the review away
New commits keep the thread honest. Rewrite after review has started hides what people already read.
Lesson review
You can read a contributing guide, pick fork or write-access branch, keep the change small, open the pull request against the original repository, and answer review without rewriting shared history. The unit project that walks a full reviewed pull request is Git Project: Reviewed Pull Request. A check reviewers can trust is GitHub Actions.
- I know
CONTRIBUTING.mdis a Git file GitHub surfaces, not agit contributecommand. - I can choose fork (no write access) versus a feature branch on the original (write access).
- I can open
gh pr create --repo ORIGINAL/REPOfrom a fork head, or a same-repo pull request when I already have write access. - I answer requested changes with
git pushon the same branch, not with force-push orgit push upstream main.