Academy · Intermediate · 15 min

Git and GitHub Pages: publish a website for free

Learn commits, branches and how to put a static website online with GitHub Pages at no cost.

Git records the history of your files. GitHub stores your repository online, and GitHub Pages can serve a static website from it for free. GM itself is published this way.

git init git add . git commit -m "First version" git branch -M main git remote add origin https://github.com/YOUR-NAME/YOUR-NAME.github.io.git git push -u origin main

Steps

  1. Create a repository named your-username.github.io.
  2. Put an index.html in it and push as above.
  3. In the repository, open Settings, then Pages, and choose the main branch.
  4. Your site appears at https://your-username.github.io within a minute or two.

Good habits

  • Commit small changes with clear messages.
  • Run git pull --rebase before you push if others (or bots) also commit.
  • Never commit passwords, API keys or private files. Add them to .gitignore.
  • Turn on two-factor authentication for your GitHub account.