DEV Community

Cover image for How to build a Weather Converter with HTML, CSS and Vanilla JavaScript (Part 4-Deployment)
Jessica Wilkins
Jessica Wilkins

Posted on

How to build a Weather Converter with HTML, CSS and Vanilla JavaScript (Part 4-Deployment)

In the last part of this tutorial, we will deploy our project to GitHub pages.

How to create a GitHub repository

Go to https://github.com/ and Sign in to your account. If you don't have an account, then you can create a free one.
github signin
github sign in page

Once you are signed in, go to the upper right hand corner and click on New Repository.
new repo

Create a short name for the repository.
add name for repo

Then you can add an optional description.
optional description

Make sure your repository is set to public.
public repo

Then click on the green Create Repository button.
green repo button

You should see this page in your GitHub.
how to setup local repo

How to add a local project to your GitHub repository

Go back to Visual Studio Code, and open up your terminal.
open terminal

In the terminal, double check to make sure you are in the project folder.
project folder terminal

Git should come installed on Linux and Mac computers. For Windows, please follow these instructions on how to install Git.

In the terminal, we will first add a README.md file using the touch command. This file describes what the project is to other users.

touch README.md
Enter fullscreen mode Exit fullscreen mode

You should see our new file show up in the Explorer tab.
new readme file

Open up the README.md file, and add a short sentence describing your project.

weather message

The .md stands for Markdown which is a language you can use to format your text. If you want to learn more about Markdown, then please visit the documentation.

If you want to learn more about how to create a good README, then please read through this article.

In the terminal, add a .gitignore file using the touch command. This file tells the computer to ignore certain files when pushing to GitHub.

touch .gitignore
Enter fullscreen mode Exit fullscreen mode

adding gitignore

Open up the .gitignore file in VS Code and add the DS_Store to it.

**/.DS_Store
Enter fullscreen mode Exit fullscreen mode

A DS_Store file was created when we created the project folder but it doesn't need to be added to GitHub.

Go back to the terminal, and initialize a new Git repository.

git init
Enter fullscreen mode Exit fullscreen mode

Then we need to add all of our files using the add command.

git add .
Enter fullscreen mode Exit fullscreen mode

Then we need to add a message for adding all of these files using the -m flag for our git commit.

git commit -m "adding project files"
Enter fullscreen mode Exit fullscreen mode

You should see all of the files we want to add in the terminal.

all committed files

Then we need to create a main branch for our repository.

git branch -M main
Enter fullscreen mode Exit fullscreen mode

Then we need to add our local project to the repository we just created on GitHub.
Copy the command you find here on the newly created repository page instructions which will have your GitHub username and project name.

project url

You can also find your git project url by clicking on the green Code button and copying the url.
green code button

In your terminal, paste that command you just copied and hit enter.

git remote add origin https://github.com/jdwilkin4/Weather-Converter-Project.git
Enter fullscreen mode Exit fullscreen mode

Lastly, run this command in your terminal and hit enter.

git push -u origin main
Enter fullscreen mode Exit fullscreen mode

You should see this message in the terminal.
success message

Go back to your GitHub profile and refresh the browser to see all of the project files.
github repo pic

That is how to create a new repository in GitHub using Git. Now, whenever you make changes to a project, Git will track those changes and you can push them to your repository on GitHub.

Deploy our project to GitHub pages

The final stage is to deploy our project using GitHub Pages. GitHub Pages is a free way to create static websites for your GitHub projects.

In the project repository on GitHub, click on the settings tab.
github settings

On the left hand side, click on the Pages option.
pages option

Under Source, make sure to choose the main branch.
source

Then click on the Save button.
click on the save button

You should see a message which includes the url for your new project.
project url

Click on the project URL, and see your new project live.
live project

That is how you deploy a project using GitHub Pages.

If you are interested on learning how to add a custom domain, then read through the GitHub documentation.

Thank you for making it through the entire 4 part series on How to build a Weather Converter with HTML, CSS and Vanilla JavaScript. 😄

You can view all of the source files for the final project in my GitHub repo.
Final project

Top comments (2)

Collapse
 
stern77 profile image
Stern77

I used your article to get familliar with Java Script in VS Code and I like it.
Many years ago I used to code with MS Visual C++ but I almost forgot everything.
With your articel I could fast get back into coding again.
So, thank you very much :)

A hint from my side:
On page 1 you write that one should add the line...
<script src="index.js"></script>

... by saying:

Inside the body tags, add a script tag for the index.js file.

...but it seems to be important to keep this at the end of the body section. At least my browser (firefox) did not make the page assign it's functionality unless I put this line right before the closing tag of section "body".

Collapse
 
mhasan profile image
Mahmudul Hasan

Good article for new coders!