top of page
  • Anwaarul Haque

Step-by-Step Guide: Deploying to GitHub Pages


'Step-by-Step Guide: Deploying to GitHub Pages,' featuring a GitHub logo and a webpage deployment process


Are you looking to showcase your project, portfolio, or documentation to the world? GitHub Pages offers a simple and free way to host static websites directly from your GitHub repositories. In this guide, we'll walk you through the steps to deploy your website to GitHub Pages, complete with examples to help you along the way.


Prerequisites


Before we dive into the deployment process, ensure you have the following:

  1. GitHub Account: You need a GitHub account to host your website using GitHub Pages.

  2. Git Installed: Make sure Git is installed on your computer. You can download it from git-scm.com.

  3. Static Website: Prepare your website as a collection of HTML, CSS, and JavaScript files.


Step 1: Create a GitHub Repository


  1. Log in to your GitHub account and navigate to the main page.

  2. Click on the +" icon in the top-right corner and select "New repository".

  3. Name your repository. Ensure it follows the format <username>.github.io where <username> is your GitHub username. This naming convention is crucial for GitHub Pages to recognize it as a personal site.

  4. Optionally, add a description for your repository.

  5. Choose whether your repository will be public or private. For hosting a GitHub Pages site, it must be public.

  6. Click "Create repository".


Step 2: Clone the Repository


To start working with your repository locally, you need to clone it to your computer.


Replace yourusername with your actual GitHub username.


Step 3: Add Your Website Files


Copy your website files (HTML, CSS, JavaScript, images, etc.) into the cloned repository folder.

Step 4: Commit and Push Changes

Once your files are in place, commit them to your local repository and push them to GitHub.

git add .
git commit -m "Initial commit"
git push origin master

Step 5: Set Up GitHub Pages


  1. Go to your repository on GitHub.

  2. Click on the "Settings" tab.

  3. Scroll down to the "GitHub Pages" section.

  4. Under "Source", select "master branch" from the dropdown menu.

  5. Click "Save". GitHub Pages will now build your site from the master branch.


Step 6: Access Your Website


After a few moments, your site should be live at https://yourusername.github.io. Congratulations, you've successfully deployed your website using GitHub Pages!


Example

For a practical example, let's say you have a simple portfolio website consisting of an index.html, styles.css, and script.js. You would follow the steps outlined above, ensuring these files are placed in your repository before pushing to GitHub.

yourusername.github.io/
│   index.html
│   styles.css
│   script.js
│   ...

Conclusion

GitHub Pages provides a straightforward way to host your static websites for free. By following these steps, you can deploy your projects, portfolios, blogs, or documentation with ease, making them accessible to a global audience.

3 views0 comments
bottom of page