Skip to content

Instantly share code, notes, and snippets.

@kevincolten
Last active October 24, 2023 00:11
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevincolten/315e27402f97a66def62 to your computer and use it in GitHub Desktop.
Save kevincolten/315e27402f97a66def62 to your computer and use it in GitHub Desktop.
@post Hosting Multiple Repositories With GitHub Pages

GitHub Pages is great for building a personal or project website. It'll default to http://username.github.io, or you can even use your own custom domain name from services like Namecheap, which I will write about in another post soon.

So you set up your GitHub Page for yourself or project, but what if you want to show off some of your other projects you are working on. You can go the poor man's route, and simply just copy everything from another repository into a folder in your username.github.io repository, commit and push the changes to GitHub, and you'll be able to navigate to http://username.github.io/project.

But this comes with some seriously inconvienent and non-conventional drawbacks, such as duplication of code across repositories and manually copy/paste-ing everytime changes are made to update your hosted codebase. Good luck maintaining that.

The other, more elegant solution is to use Git Submodules. These will allow us to pull in other repositories and have them sit as a "repository within a repository" cue Inception sound effect.

The process is as follows:

  1. Via the command line, navigate to your repository

cd path/to/your/repository.github.io

  1. Add a submodule

git submodule add https://github.com/username/otherrepository

note: It must be the `https://` address
  1. Add/commit your new files

git add .gitmodules

git add otherrepository/

git commit -m "Added otherrepository submodule"

  1. Push your changes

git push origin master

  1. navigate to http://username.github.io/otherrepository

Now if you start making changes to your other repository, you'll need to update your GitHub Pages repository to reflect those changes:

  1. Via the command line, navigate to your GitHub Pages repository

cd path/to/your/repository.github.io

  1. Navigate into your submodule

cd otherrepository/

  1. Pull from you master

git pull origin master

  1. Navigate back up to your GitHub Pages repository

cd ..

  1. Add/commit your updated files

git add .gitmodules

git add otherrepository/

git commit -m "Updated otherrepository submodule"

  1. Push your changes

git push origin master

And now your changes should be reflected online.

@Quingsley
Copy link

Hello I have a project that contains several folders which are the different pages of the website and I want to publish it using gh pages is it possible??

@kevincolten
Copy link
Author

This post is pretty outdated, but yes, the directories on the hosted branch will act like nested pages of a website.

@pippim
Copy link

pippim commented Apr 26, 2023

This post is pretty outdated, but yes, the directories on the hosted branch will act like nested pages of a website.

So there is a better way to include files from other repositories on your main GitHub Pages website?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment