Hosting Your Custom Domain on GitHub
A year or so ago, while talking to an experienced developer via Out of Office, we started chatting about domain names and hosting. I mentioned that while I liked being able to store entire projects on GitHub, it would be great if I could use my own custom domain without having the .github.io extension. And this experienced developer explained that yes, I could. In this article, I will explain how you can do this too. I will link all these steps to articles explaining each step in detail, in case you are a very newbie-newbie.
Create a GitHub account. Every aspiring developer needs a GitHub account. This is where you store your code so that if if your laptop falls into the ocean (or you spill coffee on it, etc, etc, etc) you will still have access to that multi-million dollar app you’ve been working on. Click here for more info on getting started: GitHub-Newbie
Learn git. I hardly come across developer job postings that don’t mention some sort of version control, and git is the most popular one used. You need to know git if you would like to use GitHub. It’s pretty easy to get started with both and the sooner you get started, the better. Learn git for free with Codecademy’s Learn git course.
Create your dream project on your local machine. It doesn’t need to have more than your basic index.html file(You can always add more stuff later, which is the point of using git and GitHub). This is where I suggest you learn the command line (also another must have tool in any dev’s tool-kit.(Side-note, I am no where near as proficient as I would like to be in using these tools but knowing the very basics is more than enough to get you started)
- In your terminal(if you are using Mac) or command line/git bash (for Windows users) go to the folder you are are working in. Typically, you use the cd command.
- Say your dream project is titled “dream-project”. In your terminal, type “cd dream-project”
- Once you are in your project, you need to initialize it with git.
This is your starting line.
- git init begins your project
- add your changes with git add .
- Commit your changes with git commit -m “Initial commit”. I always start out with “initial commit” just to get the ball rolling, but you can put whatever you want into that message.
- Once you have committed your changes locally, you can now push your project to GitHub. Make sure you have an identical project name on GitHub to push these changes to. GitHub will give you directions on what to type into your command line to make the push live. (This is why it’s important to actually know how to use GitHub to begin with)
So now that you’re a git, github and command line power user, and you’ve initialized your repo on your local machine and pushed the changes to github, you would like the whole world to see you awesome dream-project. Now, with what you’ve done so far, the world can actually see your dream project, except they would be seeing it as yourname.github.io/dream-project. Doesn’t seem very professional, does it? After all if this is your dream project would it kill you to pay a few bucks to host it? Well, with github, you actually can use your own customized domain name for free.
- Purchase you custom domain name — GoDaddy is the big boss around town, but there are other options and I personally like using Namecheap. Check them out to compare prices.
- Is your “dream-project” domain name available? Get it! Typically, you want to go with .com, but all the other myriads of extensions also work. At this point, it’s all about your personal preference, and your price range of course.
- Now that you’ve purchased your domain name, head back to Github.
- Go to the Settings of your Repo, and there will be a field asking for a custom domain. Enter your domain name there.
- At this point, you will need to create a CNAME file. GitHub will actuallly tell you do this after you enter in your custom domain name. Go to your repo, title it CNAME(must be in all caps) and within the file itself, just type in the name of your domain name(dreamproject.com)
- Go back to your domain host provider. You should now have an account with them to manage your domain names. Select what domain name you want to manage, and if you’re using NameCheap, select the Advanced DNS settings.
- Not only can you host your site on github for free with your custom url, github, you can also enable https on your site, just by checking the “Enforce HTTPS” box under the custom domain name! You don’t have to pay for an SSL certificate, and the process is so easy.
I know this felt like a lot, but if you are a newbie newbie, you will need to know all these things. And your dream project will be live!