So, I've been building my website for the past few weeks, and I think I'm ready to put it out on display for the public eye. However, I have no idea how to host it. I want to use github to host it, and I read everything online on how to host it on there, but I got really confused and their advice didn't work. Does anyone have any idea on how to host a website on github? and if so could you show me a step by step way?
Thank you so much:)
Github pages will guide you in a step-by-step way : https://pages.github.com/
http://jmcglone.com/guides/github-pages/ has a more elobarate guide.
And for custom domain do look at https://help.github.com/articles/setting-up-a-custom-domain-with-github-pages/
Now open up terminal (command prompt on Windows) and make sure that you have a copy of your GitHub repo on your computer. Once you got your local copy, move into the project folder using the cd command.
// Retrieve a copy of your GitHub repo.
git clone https://github.com/user/repository.git
// Move into that directory.
cd repository
Note: Make sure that you change the clone URL to the URL of your GitHub repo. This can be found on the main project page.
Creating an Orphan Branch Now you need to create a new orphan branch within your repo that will hold all of your website files.
This new branch should be called gh-pages.
git checkout --orphan gh-pages
If you already had files in the master branch of your GitHub repo you now need to delete these from the new gh-pages branch. To do this you can use the following command:
git rm -rf .
Adding Your Website Files Now that your repo has been properly setup it’s time to add all of the HTML, CSS and JavaScript files that make up your website. Once you have added these to your repo you need to commit the changes. To do this you can use the following command.
git commit -a -m "Adding pages"
Note: The -a flag is shorthand for git add .
Pushing Your Changes to GitHub Okay so you’ve got all your files where they need to be. The only thing left to do now is to push the new gh-pages branch up to GitHub. You do this using the git push command.
git push origin gh-pages
That’s it! Your website should now be available at http://username.github.io/repository/.
Using a Custom Domain The last thing I want to cover in this post is how you can use your own domain name with your new GitHub-hosted website.
First you will need to create a new file in your GitHub repo called CNAME that contains the domain name (or subdomain) that you wish to use. This file should be placed in the gh-pages branch if you are using project-pages (as we have been in this post). If you are using user-pages the file should be placed in the master branch.
Your CNAME file might look like the following:
teamtreehouse.com
Next you will need to update the DNS records for your domain name. This is usually done through a control panel provided by your domain registrar.
If you want to use a root domain (such as teamtreehouse.com) for your website you will need to setup a new A record that points to the IP address 204.232.175.78.
If you are using a subdomain (such as blog.teamtreehouse.com) it’s best to create a new CNAME record that points to your GitHub user subdomain (username.github.io). This is so that the DNS will be automatically adjusted if the servers IP address changes on GitHub.
You can check the full article here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With