DEV Community

Programming Liftoff
Programming Liftoff

Posted on

Upload a Website to GitHub Pages

This article was originally published on programmingliftoff.com as Upload a Website to GitHub Pages.

Finished Website

Note: Before following these steps you should have created a website on your local machine. If you do not have a website yet, complete the tutorial Create a Basic Webpage with CSS and JavaScript to create a website, then come back to this tutorial.

Prefer to watch this tutorial instead of reading it? Click here.

You will need git installed on your computer to upload your website to GitHub. If you don’t have it installed, visit this site and follow the instructions for your operating system. Note that if you’re using Windows, I recommend installing GitHub for Windows.

Then, to set up git, type the following in the terminal (or Git Bash on Windows), replacing <name> and <email> with your name and email:

git config --global user.name <name>
git config --global user.email <email>
Enter fullscreen mode Exit fullscreen mode

After installing and configuring git, log into GitHub and create a new repository. Do not check the box to initialize the repository with a readme. GitHub will then show you instructions for creating a new repository on the command line.

Next, open the terminal (or the ‘Git Bash’ program in Windows). Then use the cd command to navigate to the folder that your website is in. Once in the folder, type the commands that GitHub displayed after creating a new repository in the last step. The commands will be similar to the following, with only the GitHub repository URL changing:

git init
git add .
git commit -m “Upload website”
git remote add origin git@github.com:programming-liftoff/github-pages-first-upload.git
git push -u origin master # If this command fails, click the link in the next section to learn how to setup a SSH key with GitHub.
Enter fullscreen mode Exit fullscreen mode

Permission denied (publickey) when executing git push -u origin master

If you see the message "Permission denied (publickey)", you will need to setup a SSH key to use with GitHub. To do this, read GitHub's article Generating a New SSH Key. Complete all the steps, and when you're done, be sure to Add your SSH Key to your GitHub Account.

Now try executing the line git push -u origin master and it should work!

Final Steps

Finally, go to the ‘Settings’ tab of the GitHub repository, scroll down to the GitHub Pages section, choose ‘Master Branch’ for the source, and click ‘Save’. A URL will then be displayed in the GitHub Pages section. Click on that URL to visit your webpage (Note: It may take several minutes for the webpage to show up at the URL).

Congratulations! You have now uploaded you website live on the internet! Feel free to post the URL to your website in the comments below so other people can checkout your sweet website!

If you had any trouble, watch the video tutorial on YouTube.

Thanks for reading!
-Andrew @ Programming Liftoff

Top comments (0)