# Week 3

Last week, we used JavaScript to make a button display a fun fact. So far, all of our work has lived in one folder on our own computer. This week, we will start saving that work with Git and sharing it through GitHub.

We will use two parts of VS Code. The Source Control view shows our changed files and gives us buttons for common Git actions. The terminal lets us give Git commands directly. Both work with the same folder and the same history.

We will still open the page in a browser to test it. Our code stays in VS Code, and we will publish it through Source Control.

By the end of this hour, your local `<span class="editor-theme-code">main</span>` branch should be published and a second branch should contain one tested, pushed change. We will also walk through a pull request and partner review. If your pair needs more time for that part, use the review steps below to finish it during catch-up before the shared project starts in Week 9.

## Git and GitHub

Git is a version control system. It records versions of our files so we can see what changed over time. If a button stops working, that history can help us find the change that caused the problem.

A project stored with Git is called a repository, or repo. Each saved version is called a commit. A commit contains the changes we chose and a short message that explains them.

GitHub stores Git repositories online so other people can work with us. Git records the history on our computer. GitHub gives the team a shared copy of that history.

The copy on GitHub is called a remote repository. Git usually gives the main remote the short name `<span class="editor-theme-code">origin</span>`. Pushing sends local commits to the remote. Pulling brings remote commits back to our computer.

[![image.png](https://wiki.sitblueprint.com/uploads/images/gallery/2026-10/scaled-1680-/image.png)](https://wiki.sitblueprint.com/uploads/images/gallery/2026-10/image.png)

## Opening the terminal

Open the `<span class="editor-theme-code">practice-page</span>` folder in desktop VS Code. You should see `<span class="editor-theme-code">index.html</span>`, `<span class="editor-theme-code">styles.css</span>`, `<span class="editor-theme-code">script.js</span>`, and `<span class="editor-theme-code">avatar.svg</span>` in the Explorer.

Choose **Terminal &gt; New Terminal**. The terminal opens at the bottom of VS Code. A terminal lets us type commands for the computer to run. Type each command after the prompt and press Enter. Do not include the word `<span class="editor-theme-code">sh</span>` from the labels above the code blocks.

Start by checking that Git and GitHub CLI are available and that GitHub CLI knows which account to use:

```sh
git --version
gh --version
gh auth status
```

The first two commands should show version numbers. The last command should show your GitHub username and say that you are logged in to `<span class="editor-theme-code">github.com</span>`. If it does not, return to the [GitHub CLI setup](../setup.md#sign-in-through-github-cli) before continuing.

Next, check the name and email Git will store with your commits:

```sh
git config --global --get user.name
git config --global --get user.email
```

If either command shows nothing, return to the [Week 3 setup](../setup.md#tell-git-who-you-are) and add the missing value before continuing.

## Creating the repository

Select the **Source Control** icon on the left side of VS Code. It looks like a line with connected circles. Choose **Initialize Repository**.

Initializing creates Git's history inside the folder. It does not publish the files or change what the page looks like. You may notice letters beside the filenames in Source Control. `<span class="editor-theme-code">U</span>` means a file is untracked, so Git has not saved a version of it yet.

Return to the terminal and run:

```sh
git status
```

`<span class="editor-theme-code">status</span>` tells us which branch we are on and which files have changed. The four page files should appear under **Untracked files**. If you see files from outside `<span class="editor-theme-code">practice-page</span>`, stop and ask for help. Git may have been initialized in the wrong folder.

## Staging and committing the files

Before we make a commit, we choose which changes belong in it. This step is called staging. It stops us from saving an unrelated or unfinished change by accident.

In the Source Control view, find **Changes**. Select the plus button beside `<span class="editor-theme-code">index.html</span>`, `<span class="editor-theme-code">styles.css</span>`, `<span class="editor-theme-code">script.js</span>`, and `<span class="editor-theme-code">avatar.svg</span>`. Each file should move to **Staged Changes**.

Enter this message in the box at the top:

```text
Add my practice page
```

Select **Commit**. We now have a saved version in our local repository. Run these commands in the terminal:

```sh
git status
git log --oneline
```

`<span class="editor-theme-code">status</span>` should say there is nothing to commit. `<span class="editor-theme-code">log</span>` shows the commit we just made. The letters and numbers at the start of its line identify that commit.

## Creating the remote and publishing from VS Code

Our commit still exists only on this computer. First, use GitHub CLI to create a private repository on GitHub and connect it to this local repository:

```sh
gh repo create practice-page --private --source=. --remote=origin
git remote -v
```

`<span class="editor-theme-code">gh repo create</span>` creates the private remote repository. `<span class="editor-theme-code">--source=.</span>` means the repository in the current folder, and `<span class="editor-theme-code">--remote=origin</span>` connects the remote using the usual name `<span class="editor-theme-code">origin</span>`. We left out the `<span class="editor-theme-code">--push</span>` option, so the commit is still only on this computer.

Return to Source Control and select **Publish Branch**. If you do not see it, open the **...** menu and choose **Push**. Source Control uses the GitHub CLI credentials to upload the `<span class="editor-theme-code">main</span>` branch.

Run `<span class="editor-theme-code">git status</span>`. It should say that `<span class="editor-theme-code">main</span>` is up to date with `<span class="editor-theme-code">origin/main</span>`. You can open the repository address from `<span class="editor-theme-code">git remote -v</span>` to confirm the four files are there, but keep editing the local files in VS Code.

### Give your partner access

A private repository can only be opened by people you invite. This access setting is the one part we need to complete on GitHub's website.

Open the repository, choose **Settings &gt; Collaborators**, and invite your partner's GitHub username. Your partner should invite you to their repository too. Both people need to accept the invitation before the review. Copy the repository address shown by this terminal command and send it to your partner:

```sh
git remote get-url origin
```

## Making a branch

Our first commit is on a branch called `<span class="editor-theme-code">main</span>`. We will use `<span class="editor-theme-code">main</span>` for the version we have checked and agreed to keep.

A branch lets us work on a change separately. When we create a branch from `<span class="editor-theme-code">main</span>`, it starts with the same files. We can change the fun fact while `<span class="editor-theme-code">main</span>` keeps the original. Once someone has reviewed the change, we can merge it into `<span class="editor-theme-code">main</span>`.

Create a branch in the terminal:

```sh
git switch -c improve-fact
```

`<span class="editor-theme-code">switch</span>` moves us to another branch. The `<span class="editor-theme-code">-c</span>` option tells Git to create the branch first. The branch name appears in the lower-left corner of VS Code. You can also check it with:

```sh
git branch --show-current
```

It should say `<span class="editor-theme-code">improve-fact</span>`. The files still look the same because we have only created the branch.

## Changing and reviewing a file

Open `<span class="editor-theme-code">script.js</span>`. The Week 2 example used this line:

```js
fact.textContent = "I can solve a Rubik's Cube.";
```

Add a little more detail:

```js
fact.textContent = "I can solve a Rubik's Cube in under two minutes.";
```

If you wrote a different fact last week, add a detail to that one instead. Save the file, then run:

```sh
git status
git diff
```

`<span class="editor-theme-code">status</span>` should list `<span class="editor-theme-code">script.js</span>` as modified. `<span class="editor-theme-code">diff</span>` shows the exact lines that changed. A line beginning with `<span class="editor-theme-code">-</span>` is the old version, and a line beginning with `<span class="editor-theme-code">+</span>` is the new version. Red and green show removal and addition; they do not tell us whether the code is good or bad.

You can see the same comparison by selecting `<span class="editor-theme-code">script.js</span>` under **Changes** in Source Control. Read it before staging. Make sure only the sentence changed.

## Testing the branch

Open the same local `<span class="editor-theme-code">index.html</span>` you have been using. Click the button. The new sentence should appear. Click again to confirm it stays, then refresh and check that the starting message returns. The picture and styles should still load.

## Staging and committing in the terminal

This time, we will stage and commit with commands:

```sh
git add script.js
git diff --staged
git commit -m "Add the solving time to the Rubik's Cube fact"
```

`<span class="editor-theme-code">git add</span>` stages the file. After staging, plain `<span class="editor-theme-code">git diff</span>` no longer shows that change, so `<span class="editor-theme-code">git diff --staged</span>` shows what the next commit will contain.

The `<span class="editor-theme-code">-m</span>` option gives the commit its message. A message like `<span class="editor-theme-code">update</span>` tells us very little. Naming the change helps a teammate understand the commit without opening it.

Run `<span class="editor-theme-code">git status</span>` again. It should say the working tree is clean. The new commit is local until we push the branch:

```sh
git push -u origin improve-fact
```

`<span class="editor-theme-code">push</span>` sends the commit to GitHub. `<span class="editor-theme-code">origin</span>` identifies the remote repository, and `<span class="editor-theme-code">improve-fact</span>` identifies the branch. The `<span class="editor-theme-code">-u</span>` connects the local and remote branches, so later we can use the shorter command `<span class="editor-theme-code">git push</span>`.

## Creating a pull request in VS Code

We now have a change on `<span class="editor-theme-code">improve-fact</span>` that we want to add to `<span class="editor-theme-code">main</span>`. A pull request, usually shortened to PR, is how we propose that change on GitHub. Opening a PR does not change `<span class="editor-theme-code">main</span>`.

Select the GitHub icon in VS Code to open **GitHub Pull Requests**. The extension may ask you to connect a GitHub account the first time you open it. Choose the same account shown by `<span class="editor-theme-code">gh auth status</span>`. This connection lets the extension display pull requests; Git still uses GitHub CLI when it pushes and pulls.

Make sure the current branch is `<span class="editor-theme-code">improve-fact</span>`, then choose **Create Pull Request** and set the base branch to `<span class="editor-theme-code">main</span>`. The base receives the change from our current branch.

Read the diff and confirm it shows the sentence you meant to change. Use a title such as:

```text
Add the solving time to the Rubik's Cube fact
```

In the description, explain what changed and what happened when you tested it. For example:

> I added how long it takes to solve the Rubik's Cube. I opened the page from my improve-fact branch and tried the button. It showed the new sentence, and the picture and styles still loaded.

Write what you actually checked. Add your partner as the reviewer, then create the PR.

## Reviewing a pull request in VS Code

Your partner needs a local copy of your repository to try the change. Cloning downloads a repository, including its files and Git history.

1. Accept your partner's collaborator invitation.
2. In VS Code, open the Command Palette with **View &gt; Command Palette** and run **Git: Clone**.
3. Paste the HTTPS repository address your partner sent you. Git will use the account shown by `<span class="editor-theme-code">gh auth status</span>`.
4. Choose a parent folder that is separate from your own `<span class="editor-theme-code">practice-page</span>`. Open the cloned repository in a new VS Code window.
5. Select the GitHub Pull Requests icon, find the PR assigned to you, and open it.
6. Select **Checkout** on the PR. VS Code switches the local files to the branch from that PR.

Read the description and open **Changes in Pull Request**. Select `<span class="editor-theme-code">script.js</span>` to read the diff.

Open `<span class="editor-theme-code">index.html</span>` from the cloned folder and try the button. The sentence on the page should match the added line in the diff. If the change makes sense and works, describe what you checked and approve it. If something is unclear or broken, comment on the line or request a change. Submit the review so the author can see it.

You do not have to invent a problem. A useful approval says what you read and tested.

## Updating the pull request

If your reviewer asks for a change, return to your own `<span class="editor-theme-code">practice-page</span>` window. Make sure the lower-left corner says `<span class="editor-theme-code">improve-fact</span>`, then edit and test the file. Save another commit on the same branch:

```sh
git add script.js
git commit -m "Clarify the fun fact"
git push
```

The existing PR updates when the new commit reaches the same remote branch. Do not open another PR for the correction. Ask your partner to make sure the PR branch is checked out, run `<span class="editor-theme-code">git pull</span>` in that repository's terminal, and test it again.

## Merging and updating `<span class="editor-theme-code">main</span>`

Once the change works and your partner has approved it, return to your own `<span class="editor-theme-code">practice-page</span>` window. Open the PR description in VS Code and select **Merge**. Merging brings the branch's change into `<span class="editor-theme-code">main</span>` on GitHub.

Your local `<span class="editor-theme-code">main</span>` still needs that remote change. Return to the terminal in your own repository and run:

```sh
git switch main
git pull
```

Open `<span class="editor-theme-code">script.js</span>` and find the new sentence. Now the local and remote copies of `<span class="editor-theme-code">main</span>` both contain the reviewed change.

In Week 9, teams will receive different tasks in one shared merch repository. The repository will already exist, so you will clone it instead of publishing it. You will then use the same branch, commit, push, PR, review, merge, and pull steps from this lesson. Before that, we will learn React, product data, APIs, carts, and checkout through smaller examples.

## Before next week

Complete the [Week 4 setup](https://wiki.sitblueprint.com/books/tech-team-fa26/page/setup) before our next meeting. We will rebuild part of the practice page with React.

## Common problems

<table id="bkmrk-what-you-seewhat-to-"><colgroup><col></col><col></col></colgroup><tbody><tr><th>What you see

</th><th>What to check

</th></tr><tr><td>The terminal cannot find

`<span class="editor-theme-code">git</span>`

</td><td>Install Git, then completely close and reopen VS Code. Run

`<span class="editor-theme-code">git --version</span>`

 again.

</td></tr><tr><td>The terminal cannot find

`<span class="editor-theme-code">gh</span>`

</td><td>Install GitHub CLI, then completely close and reopen VS Code. Run

`<span class="editor-theme-code">gh --version</span>`

 again.

</td></tr><tr><td>`<span class="editor-theme-code">gh auth status</span>`

 says you are not logged in

</td><td>Repeat the

[GitHub CLI sign-in steps](../setup.md#sign-in-through-github-cli)

, then run

`<span class="editor-theme-code">gh auth status</span>`

 again.

</td></tr><tr><td>GitHub CLI shows the wrong account

</td><td>Run

`<span class="editor-theme-code">gh auth switch</span>`

. If the account you need is not listed, repeat the

[GitHub CLI sign-in steps](../setup.md#sign-in-through-github-cli)

. Then run

`<span class="editor-theme-code">gh auth setup-git</span>`

.

</td></tr><tr><td>A commit asks for your identity

</td><td>Run the two

`<span class="editor-theme-code">git config --global</span>`

 commands from setup with your own name and commit email.

</td></tr><tr><td>Source Control shows files outside

`<span class="editor-theme-code">practice-page</span>`

</td><td>Stop before committing. Check which folder is open in VS Code and ask for help finding where Git was initialized.

</td></tr><tr><td>`<span class="editor-theme-code">gh repo create</span>`

 says the repository already exists

</td><td>Stop before choosing another command. Check the existing repository with the facilitator so you do not overwrite or connect to the wrong project.

</td></tr><tr><td>**Publish Branch**

 is missing

</td><td>Run

`<span class="editor-theme-code">git remote -v</span>`

 and confirm that

`<span class="editor-theme-code">origin</span>`

 exists. Make sure the first commit is on

`<span class="editor-theme-code">main</span>`

, then look for

**Push**

 in the Source Control

**...**

 menu.

</td></tr><tr><td>The wrong sentence appears

</td><td>Run

`<span class="editor-theme-code">git branch --show-current</span>`

, save

`<span class="editor-theme-code">script.js</span>`

, and refresh the local page.

</td></tr><tr><td>The PR has nothing to compare

</td><td>Confirm you committed on

`<span class="editor-theme-code">improve-fact</span>`

 and pushed it. Run

`<span class="editor-theme-code">git status</span>`

 and

`<span class="editor-theme-code">git log --oneline</span>`

.

</td></tr><tr><td>A partner cannot clone the repository

</td><td>Check that the invitation was accepted by the account shown by

`<span class="editor-theme-code">gh auth status</span>`

, then run

`<span class="editor-theme-code">gh auth setup-git</span>`

 and try the HTTPS address again.

</td></tr><tr><td>The Pull Requests view shows the wrong account

</td><td>Sign out of that extension account and connect the same account shown by

`<span class="editor-theme-code">gh auth status</span>`

.

</td></tr><tr><td>`<span class="editor-theme-code">main</span>`

 still has the old sentence after merging

</td><td>Switch to

`<span class="editor-theme-code">main</span>`

, run

`<span class="editor-theme-code">git pull</span>`

, then reopen or refresh the file.

</td></tr></tbody></table>

## Resources

- [Install Git](https://git-scm.com/downloads)
- [Install GitHub CLI](https://github.com/cli/cli#installation)
- [GitHub CLI: Sign in](https://cli.github.com/manual/gh_auth_login)
- [GitHub CLI: Configure Git credentials](https://cli.github.com/manual/gh_auth_setup-git)
- [GitHub CLI: Create a repository](https://cli.github.com/manual/gh_repo_create)
- [VS Code: Source Control](https://code.visualstudio.com/docs/sourcecontrol/overview)
- [VS Code: Git quickstart](https://code.visualstudio.com/docs/sourcecontrol/quickstart)
- [VS Code: Repositories and remotes](https://code.visualstudio.com/docs/sourcecontrol/repos-remotes)
- [VS Code: Work with GitHub](https://code.visualstudio.com/docs/sourcecontrol/github)
- [Git: Recording changes](https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository)
- [GitHub: Invite a collaborator](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/managing-repository-settings/inviting-collaborators-to-a-personal-repository)

If you forget a command, start with the result you need. For example, search Google for `<span class="editor-theme-code">GitHub CLI create repository from existing folder</span>` or `<span class="editor-theme-code">Git show current branch</span>`. Open a result from the VS Code, Git, or GitHub documentation and compare its example with your current folder and branch before running it.