Contribute to the Codebase
Follow these guidelines to contribute to the codebase. This is highly recommended if you want to contribute regularly. Ignoring these steps may soil your copy which makes the contributing, maintaining, and reviewing processes difficult.
Contributing to the Codebase
Section titled “Contributing to the Codebase”You can now make changes to files and commit your changes to your fork, which you can prepare by reading how to set up freeCodeCamp locally.
Follow these steps:
-
Validate that you are on the
main
branch:Terminal window git statusYou should get an output like this:
Terminal window On branch mainYour branch is up-to-date with 'origin/main'.nothing to commit, working directory cleanIf you got a different message, then you aren’t on main or your working directory isn’t clean, resolve any outstanding files/commits and checkout
main
:Terminal window git checkout mainIf you get a message similar to this one:
Terminal window On branch feat/colour-pickerChanges not staged for commit:(use "git add <file>..." to update what will be committed)(use "git restore <file>..." to discard changes in working directory)modified: curriculum/i18n-curriculum (new commits)Then the i18n curriculum submodule is out of sync. You should NOT commit changes to the submodule through our main repository. Instead, to resolve this, run:
Terminal window git submodule update --init -
Sync the latest changes from the freeCodeCamp upstream
main
branch to yourmain
fork branch:This step will sync the latest changes from the main repository of freeCodeCamp.
Update your copy of the freeCodeCamp upstream repository:
Terminal window git fetch upstreamHard reset your main branch with the freeCodeCamp main:
Terminal window git reset --hard upstream/mainPush your main branch to your origin to have a clean history on your fork on GitHub:
Terminal window git push origin main --forceYou can validate that your current main matches the upstream/main by performing a diff:
Terminal window git diff upstream/mainThe resulting output should be empty. This process is important, because you will be rebasing your branch on top of the latest
upstream/main
as often as possible to avoid conflicts later. -
Create a fresh new branch:
Working on a separate branch for each issue helps you keep your work copy clean. You should never work on the
main
. This will soil your copy of freeCodeCamp and you may have to start over with a fresh clone or fork.Check that you are on
main
as explained previously, and branch off from there:Terminal window git checkout -b fix/update-guide-for-xyzYour branch name should start with a
fix/
,feat/
,docs/
, etc. Avoid using issue numbers in branches. Keep them short, meaningful and unique.Some examples of good branch names are:
fix/update-challenges-for-reactfix/update-guide-for-html-cssfix/platform-bug-sign-in-issuesfeat/add-guide-article-for-javascripttranslate/add-spanish-basic-html -
Edit pages and work on code in your favorite text editor.
-
Once you are happy with the changes you should optionally run freeCodeCamp to preview the changes.
-
Make sure you fix any errors and check the formatting of your changes.
-
Check and confirm the files you are updating:
Terminal window git statusThis should show a list of
unstaged
files that you have edited.Terminal window On branch feat/documentationYour branch is up to date with 'upstream/feat/documentation'.Changes were not staged for commit:(use "git add/rm <file>..." to update what will be committed)(use "git checkout -- <file>..." to discard changes in the working directory)modified: CONTRIBUTING.mdmodified: docs/README.mdmodified: docs/how-to-setup-freecodecamp-locally.mdmodified: docs/how-to-work-on-guide-articles.md... -
Stage the changes and make a commit:
In this step, you should only mark files that you have edited or added yourself. You can perform a reset and resolve files that you did not intend to change if needed.
Terminal window git add path/to/my/changed/file.extOr you can add all the
unstaged
files to the staging area:Terminal window git add .Only the files that were moved to the staging area will be added when you make a commit.
Terminal window git statusOutput:
Terminal window On branch feat/documentationYour branch is up to date with 'upstream/feat/documentation'.Changes to be committed:(use "git reset HEAD <file>..." to unstage)modified: CONTRIBUTING.mdmodified: docs/README.mdmodified: docs/how-to-setup-freecodecamp-locally.mdmodified: docs/how-to-work-on-guide-articles.mdNow, you can commit your changes with a short message like so:
Terminal window git commit -m "fix: my short commit message"Some examples:
fix: add test for JavaScript - for loop stepfeat: add link for article for alexa skillsMake a conventional commit message. This is a good practice as a developer, and you will be following standard practices.
Some examples of conventional commit messages are:
fix: improve HTML stepfix: fix build scripts for Travis-CIfeat: add link to JavaScript hoisting articledocs: update contributing guidelinesKeep these short, not more than 50 characters. You can always add additional information in the description of the commit message.
This does not take any more time than an unconventional message like ‘update file’ or ‘add index.md’
You can learn more about why you should use conventional commits here.
-
If you realize that you need to edit a file or update the commit message after making a commit you can do so after editing the files with:
Terminal window git commit --amendThis will open up a default text editor like
nano
orvi
where you can edit the commit message title and add/edit the description. -
Next, you can push your changes to your fork:
Terminal window git push origin branch/name-here
Proposing a Pull Request (PR)
Section titled “Proposing a Pull Request (PR)”After you’ve committed your changes, check here for how to open a Pull Request.
Quick commands reference
Section titled “Quick commands reference”A quick reference to the commands that you will need when working.
command | description |
---|---|
pnpm test | Run all JS tests in the system, including client, server, lint and challenge tests. |
pnpm run test-client | Run the client test suite. |
pnpm run test-client -u | Run the client test suite, updating the Jest snapshots that are out of sync. |
pnpm run test:curriculum | Run the curriculum test suite. |
FCC_CHALLENGE_ID=646cf6cbca98e258da65c979 pnpm run test:curriculum | Test a specific Challenge. |
FCC_BLOCK='Basic HTML and HTML5' pnpm run test:curriculum | Test a specific Block. |
FCC_SUPERBLOCK='responsive-web-design' pnpm run test:curriculum | Test a specific SuperBlock. |
pnpm run test-curriculum-full-output | Run the curriculum test suite, without bailing after the first error |
pnpm run test-server | Run the server test suite. |
pnpm run playwright:run | Run the Playwright end to end tests. |
pnpm run clean | Uninstalls all dependencies and cleans up caches. |
pnpm run storybook | Starts Storybook for component library development. |