To publish your site on Github pages, use the following steps in the terminal and / or Github.
- In the terminal, switch to the directory that you want to publish to Github.
- Initialize the directory.
- Shows the status of the files in the directory. Red indicates not committed. Green indicates committed.
- Start tracking the files with Git.
git add .
- Commit the files and provide a commit message.
git commit -m 'Initial Commit Message'
- Create a new repository in your Github account.
- Push the local repository to your Github account using the commands provided under the “…or push an existing repository from the command line” section.
git remote add origin https://github.com/username/repositoryname.git
git push -u origin master
- Create a local branch for the project pages site. It MUST be named gh-pages or it will not display as a website.
git checkout -b gh-pages
- Push the new branch to the remote repository. This command not only pushes the files to Github but also creates the new branch.
git push origin gh-pages
Once the gh-pages branch is pushed, it will take no more than 10 minutes for the site to be available.
Github project pages are located at the following domain: username.github.io/repositoryname
Where’d my styles go?
Github pages are hosted from a sub-path, so we need to set a base URL configuration in our project.
- Edit the
_config.ymlfile baseurl variable by adding the name of the repository with a leading slash
- Commit the files and push to the
Removing a local Git repository
rm -r .git removes the local Git repository for a project.