Connect a GitHub Account

Git is a tool for keeping track of versions of your code projects. GitHub is a platform that uses Git for publishing websites.

The following steps (1-3) lead you through installing Git on your computer, creating a GitHub account, and then linking your GitHub account to your computer. You only need to do this once; after you have successfully completed these steps, your computer should be set up for using Git and GitHub as much as you want.

  1. Download and install the latest version of Git
  2. Make a GitHub account
  3. Connect your laptop to you your GitHub account

    Here is the full documentation for this step. TLDR:

    1. Open the Terminal app on Mac or Command Prompt on Windows.
    2. Feel like a super cool coder.
    3. Set your username (doesn't technically have to be the same as your GitHub username, but it makes sense to make them match) by running the following (code in purple should be replaced with your personalized info):
      git config --global user.name "yourUserName"
    4. Set your email address (this DOES have to be the same email you used to sign up for your GitHub account):
      git config --global user.email "yourEmail@email.com"

Create a Repository

A repository stores all versions of your code and files for a project. What makes a repository different from any old folder is that its connection to GitHub allows it to track changes as you work, which you can then publish to the web.

  1. Create a new repository

    Log in to github.com. Click Create repository (sometimes this is hidden beyond a [+] button in top right corner).

    Choose a repository name.

    Your name should have no spaces (for example "IntroToComputation" or "intro_to_computation" instead of "Intro To Computation")

    Keep the repository Public.

    Click Create repository.

  2. Upload files to the repository

    On your new repository page, click uploading an existing file.

    Drag your index.html and any linked files (e.g., styles.css or any images) into the repository. (Just upload the files, not the top-level folder that contains them).

    Write a commit message (e.g., "Add files via upload" or "Initial commit") and commit your changes.

    A screenshot showing where to upload files to a GitHub repository
  3. Deploy your code to the web

    On the home page for the repository you just created, go to the Settings tab.

    On the left of the Settings page, choose Pages. Then, under Branch, select main and hit Save.

    Wait a minute or two for the servers to catch up. Then go to http://username.github.io/repositoryName (fill in your own GitHub username and the repositoryName you just chose) to see your live webpage!

    Screenshot showing the Settings tab and the place on the Pages tab of Settings where you can select the branch to deploy

Clone a Repository

The files in your GitHub repository are the files that contain the code that shows on the web. Therefore, those are the files you need to make changes in if you want to make changes to your website.

To work with your repository on your local computer, you can clone (i.e., make a copy of) the repository (instructions below). Once you have cloned a repository, you should only work in the cloned files. If you have files on your local computer that you uploaded to the repository, delete those original files and only work in the cloned files.

  1. If this is your first time cloning a repository: create a new folder called Git in the home directory of your computer. This folder is where you will hold all of your Git-tracked code projects.
    • On Mac: find your home directory by opening Finder and typing Command-Shift-H, or add the directory to the Finder toolbar in Finder>Preferences.
    • On Windows: TODO: idk how to find the home directory on Windows :) someone with a Windows computer will have to help me
  2. Open the Terminal app on Mac or Command Prompt on Windows.
  3. Use the command line to navigate into your Git directory by running
    cd Git
  4. Copy the web URL of your GitHub repository, which you can find by clicking the green <> Code button on the repository page in GitHub.
    Screenshot showing the Code button and web URL on a GitHub repository homepage
  5. Run the following in the command line to make a clone of your repository on your computer.
    git clone https://yourUrlHere
  6. Now you should see a new folder with your new repository inside of your Git folder. Open that folder in Visual Studio Code.

    And you're read to keep coding!

Note: Once you have cloned your repository, delete the original files that you uploaded to GitHub. From now on, only work on the cloned version, because those are the files that are tracked by Git and you will be able to publish to the web.

Commit and Sync Changes

When you're satisfied with the edits you have made to your website, you can Commit your changes and then Sync them to GitHub and the web.

VS Code has tools for viewing, committing, and syncing changes to GitHub repositories (here is the full documentation).

  1. Click the branching icon on the left-side toolbar to open up the Source Control view.

    A screenshot of VS Code that shows the branching icon leading to Source Control view
  2. Click on a file to open a side-by-side "Working Tree" (aka, "the diff") showing the changes you have made since the last commit.
  3. If you are satisfied with the changes, click the "+" icon on that file to stage the changes.
    A screenshot of VS code showing how to use the + icon to stage changes
  4. When you have staged all desired changes, type a commit message in the Message bar and click Commit.
    • A commit message should be a few words or a sentence describing the changes you are committing. It is best practice to make your commit messages specific, e.g., instead of "made some changes", write "updated font colors for headings".
  5. To push your changes to your published web page, click the Sync button.
    • The first time you do this, VS Code may open a browser window to connect with your GitHub account. Log on and allow GitHub to access your computer.

Once you have synced, it may take a few minutes for your changes to show up, but eventually you should see them at the URL for your repository (http://username.github.io/repositoryName).