Set Up the Site and Git

In the last lesson, you looked at deals.js, deals-old.js, and deals-FINAL2.js and found that three handmade copies can’t tell you which version is live or what changed between them. Git can, but only once it’s on your computer and knows who you are.

In this lesson, you’ll get the store’s site running, install Git, and give it the few settings that every commit you make will rely on. By the end, the project’s own check script will confirm that Git is installed. Start with the part you already know, which is getting the site onto your screen.

Run the Store’s Site

Before you change how you track a project, it helps to know that it works. The site in the generic-grocery folder you unzipped is plain HTML, CSS, and ES modules, so there’s nothing to install for it.

As the README’s “Run it” section says, it needs a local server because browsers don’t load modules from a page opened straight from disk.

Open the generic-grocery folder in VS Code with File → Open Folder…. Then right-click index.html and choose Open in Integrated Browser to preview the page right in VS Code.

Take a moment to look at what the page shows. Near the top, a line starts with Today: and gives today’s opening hours, such as 7 a.m. to 9 p.m. on a weekday. Below it are the weekly hours and the holiday hours:

The Generic Grocery Co. homepage in a browser, showing a green header, a "Today: 7 a.m. to 9 p.m." line, a weekly opening hours table, and Christmas holiday hours.

If you only see the placeholder text Today’s hours, then the JavaScript didn’t update the page. The most common cause is a page opened from disk, for example by double-clicking index.html so it opened in your browser.

Click Weekly deals in the navigation too. It lists eight deal cards, from large brown eggs at $3.99 a dozen to a 12 oz bag of fresh cranberries at $2.79. These cards come from src/deals-page.js, which imports src/data/deals.js, so of the three deals files, deals.js is the one the site reads today.

Finally, open a terminal inside VS Code with Terminal → New Terminal. It starts in the project folder, which is where every command in this lesson runs.

Install Git

The project comes with a small script that inspects its Git setup, scripts/check.js. You’ll run it many times in this course, and its first check answers the question that you may have right now, which is whether this computer already has Git. Run it with Node.js by typing node scripts/check.js in the terminal. On a computer without Git, the report looks like this:

Language: Program Output
Checking the Git repository in /Users/username/projects/generic-grocery

✘ Git isn't installed, or your terminal can't find it.
  Next step: install Git, then open a new terminal.

1 check(s) failed.

The first line shows your own project folder, so your path will differ. The ✘ marks a check that failed, and the “Next step” line under it says what to do about it. If your report includes a ✔ and “Git is installed” instead, then you already have Git, and you can skip ahead to checking its version below.

Git installs differently on each system, so pick yours:

Windows comes with winget, a package manager that installs programs from the terminal. Install Git for Windows with it:

Language: Windows PowerShell
PS> winget install --id Git.Git -e --source winget

If your Windows installation doesn’t have winget, download the installer from the official Git website, and keep the suggested option on every screen. You’ll choose the editor and the branch name with Git’s own settings in a moment.

When the installation finishes, close VS Code completely and open it again. The installer adds Git’s folder to the list of places Windows searches for programs, and a terminal in VS Code gets that list from VS Code when it starts. Restarting VS Code lets its new terminals pick up the change.

Install Git with your distribution’s package manager. On Ubuntu and Debian, update the package list first, and then install Git:

Language: Shell
$ sudo apt update
$ sudo apt install git

On Fedora, the command is sudo dnf install git.

macOS includes a placeholder for Git that offers to install Apple’s command-line developer tools the first time you use it. Ask Git for its version:

Language: Shell
$ git --version

If a window asks whether to install the command-line developer tools, click Install and wait until it’s done. Then open a new terminal. If you already use Homebrew, brew install git works too.

Now check that the terminal finds Git by asking for its version:

Language: Shell
$ git --version
git version 2.43.0

Your number may be higher. On Windows, the version ends in .windows.1, and Apple’s Git adds (Apple Git-...) at the end. Any current version works for this course.

If git --version still reports that the command isn’t found, even in a new terminal, you can ask the mentor for help. The button below opens a conversation that has this question already filled in. Add your system and the exact message you see before you send it, and the mentor walks you through what to check.

With Git in place, run node scripts/check.js again. This time, the report gets one step further:

Language: Program Output
Checking the Git repository in /Users/username/projects/generic-grocery

✔ Git is installed (git version 2.43.0).
✘ This folder isn't a Git repository yet.
  Next step: run git init in the project folder.

1 check(s) failed.

The first check passes now. The second one fails, which is expected at this point. Don’t run git init here yet, even though the script suggests it. You’ll try Git in a throwaway practice folder first, and the store’s site gets its repository later, once one safety step is in place.

Tell Git Who You Are

Every commit records who made it, so Git needs a name and an email address before you make your first one. You set them once with git config, and the --global option stores them for your user account, so they’re the default for every repository on this computer. Type your own name and email instead of the placeholders:

Language: Shell
$ git config --global user.name "Firstname Lastname"
$ git config --global user.email "[email protected]"

These two commands don’t print anything when they work. The settings are labels that Git copies into each commit you make from now on, so anyone who reads the project’s history can see who made which change. When you share a repository on a host like GitHub later, the host uses the email to link your commits to your account there, so it’s worth using the address you plan to sign up with.

Setting them doesn’t sign you in anywhere or prove who you are, because anyone can type any name here. Sending work to a host is authenticated separately. Keep in mind that the email becomes visible to everyone who can see your commits once you share them. That’s all you need to know about your identity for now.

Before you set the rest, check that the difference between these labels and signing in is clear. The button below starts a short quiz with the mentor about how commits use your name and email. The mentor asks one question at a time, waits for your answer, and then tells you what you got right and what to look at again.

Two more settings save you trouble later. The first is the name of the initial branch in a new repository. A branch is a line of commits, and you’ll work with branches in a later course. Git 2.43 calls the first one master and prints a hint every time you create a repository, while GitHub and most teams use main. Set main as your default:

Language: Shell
$ git config --global init.defaultBranch main

You’ll still see master in older repositories and tutorials, and it works the same way.

The second setting is the editor Git opens when it needs you to write a longer message. Out of the box, that’s often Vim. Vim is a terminal editor that has a reputation of being confusing when you meet it by surprise. You can sidestep this by telling Git to use VS Code instead:

Language: Shell
$ git config --global core.editor "code --wait"

The --wait part makes Git wait until you close the editor tab before it continues. On macOS, the code command exists only after you run Shell Command: Install ‘code’ command in PATH from VS Code’s Command Palette. You can confirm it works on any system with code --version, which prints VS Code’s version number.

Now look at everything you’ve set:

Language: Shell
$ git config --global --list
user.name=Firstname Lastname
[email protected]
init.defaultbranch=main
core.editor=code --wait

Why does it say defaultbranch in lowercase when you typed defaultBranch? Git treats setting names like these as case-insensitive and lists them in lowercase, so both spellings mean the same setting. If one of your lines is missing or has a typo, run its git config command again, and the new value replaces the old one.

Your computer is ready. The site runs, Git is installed, and every commit you make will carry your name and email. New repositories will start on main, and Git will open VS Code when it needs a message from you.

Check Your Setup

Before you move on, test yourself with these questions about the setup you’ve finished:

  1. Which command shows the settings you chose, and which four settings should it list?
  2. You change user.email next month. What happens to the commits you’ve already made?
  3. Why does node scripts/check.js still report a failed check, and why is that fine for now?
  1. git config --global --list shows them. You should see user.name, user.email, init.defaultbranch=main, and core.editor=code --wait.

  2. Nothing happens to them. Git copied the old email into each of those commits when you made them, so only new commits get the new address.

  3. The project folder isn’t a Git repository yet. That’s on purpose, because you’ll practice in a separate folder first and set up the store’s repository later.

You haven’t seen Git record anything yet. In the next lesson, you’ll create a small throwaway folder from the same store and turn it into your first repository, so that you can make a mistake without anything being at stake.

Become a Member to join the conversation.