Skip to content

Lab 1: Terminal & Git Basics

Goal

Set up your terminal environment, clone a local starter repo into a disposable lab workspace, navigate it, and make your first git commit. By the end, you'll feel comfortable in the command line and understand how git tracks changes.

Estimated time: 20–30 minutes

Prerequisites

  • A computer (macOS, Linux, or Windows with Git Bash or WSL)
  • A local copy of this course repo
  • Administrator access to install software (if needed)

Operating System-Specific Setup

macOS

  1. Open FinderApplicationsUtilitiesTerminal.app
  2. Right-click on Terminal, select "Move to Dock" (optional, but convenient)
  3. You're ready. macOS ships with git pre-installed.

To verify git is installed:

$ git --version
git version 2.39.0 (or later)

If you don't see a version, you may need to install Xcode Command Line Tools:

$ xcode-select --install

Linux (Ubuntu/Debian)

Open any terminal and verify git is installed:

$ git --version

If not installed:

$ sudo apt-get update
$ sudo apt-get install git

Windows

Heads up: Windows native PowerShell works, but we recommend Git Bash (ships with Git for Windows) or WSL for this course. The commands below assume a Unix-style shell.


Step 1: Verify Your Terminal Works

Open your terminal and run:

$ pwd

Expected output (will differ based on your username and machine):

/Users/yourname
or
/home/yourname

If you see this, your terminal is working. Move to Step 2.

Troubleshooting: If the terminal won't open, restart your computer or check OS documentation.


Step 2: Create a Workspace Folder

You'll keep disposable lab work separate from the course files. Let's create a workspace for copies you can safely edit.

$ cd ~
$ mkdir -p opencode-labs
$ cd opencode-labs
$ pwd

Expected output:

/Users/yourname/opencode-labs
(on macOS) or /home/yourname/opencode-labs (on Linux).


Step 3: Clone the Starter Repo

We've prepared a starter repo with a simple Node.js project. Clone the local starter from your course repo into the disposable workspace.

First, find your course repo root. In the directory where this course lives, run:

$ pwd

If that prints something like /Users/yourname/Documents/opencode-course, use that path in the clone command below:

$ cd ~/opencode-labs
$ git clone /Users/yourname/Documents/opencode-course/labs/module-01-starter module-01-starter
$ cd module-01-starter
$ ls

Expected output (contents of the cloned folder):

README.md
package.json
src/
tests/
.gitignore

If you see these files, the local clone succeeded.

Troubleshooting: - "git: command not found" — git is not installed. See Prerequisites above. - "fatal: repository ... does not exist" — Check the course repo path in the git clone command.


Step 4: Explore the Repo Structure

Let's get comfortable navigating:

$ pwd

Expected output:

/Users/yourname/opencode-labs/module-01-starter

Now list everything:

$ ls -la

Expected output (including hidden files):

total 56
drwxr-xr-x   9 yourname  staff   288 May  2 10:30 .
drwxr-xr-x   3 yourname  staff    96 May  2 10:25 ..
drwxr-xr-x   9 yourname  staff   288 May  2 10:30 .git/
-rw-r--r--   1 yourname  staff    22 May  2 10:30 .gitignore
-rw-r--r--   1 yourname  staff  1240 May  2 10:30 README.md
-rw-r--r--   1 yourname  staff   145 May  2 10:30 package.json
drwxr-xr-x   3 yourname  staff    96 May  2 10:30 src/
drwxr-xr-x   3 yourname  staff    96 May  2 10:30 tests/

The .git folder is how git knows this is a repository. Notice the dot prefix — that means it's hidden. That's why we used ls -la (the -a flag shows hidden files).


Step 5: Read the Project Structure

Let's peek at the README:

$ cat README.md

Expected output (first few lines):

# Module 1 Starter Project

A simple Node.js project to practice terminal and git basics.

## Files

- `src/index.js` — Main application
- `tests/index.test.js` — Test file
- `package.json` — Project metadata

Good! Now let's look at the source code:

$ cat src/index.js

Expected output:

// A simple function that adds two numbers
function add(a, b) {
  return a + b;
}

module.exports = { add };

And the test:

$ cat tests/index.test.js

Expected output:

const { add } = require("../src/index.js");

describe("add", () => {
  test("adds 2 + 3 = 5", () => {
    expect(add(2, 3)).toBe(5);
  });

  test("adds 0 + 0 = 0", () => {
    expect(add(0, 0)).toBe(0);
  });
});


Step 6: Check Git Status

Now let's see git's perspective. This repo was just cloned, so there should be no changes:

$ git status

Expected output:

On branch main
nothing to commit, working tree clean

Great! Everything is in sync. Now let's make a change.


Step 7: Make a Change

Edit the src/index.js file to add a new function. Use any text editor you are comfortable with, such as VS Code:

$ code src/index.js

Manually change the full file to this:

// A simple function that adds two numbers
function add(a, b) {
  return a + b;
}

function multiply(a, b) {
  return a * b;
}

module.exports = { add, multiply };

Avoid terminal redirection for this step. Replacing the wrong line with > can erase the file.

Run the tests before committing:

$ npm test

Step 8: Check Status Again

$ git status

Expected output:

On branch main

Changes not staged for commit:
  (use "git add <file>..." to stage your changes)
    modified:   src/index.js

no changes added to commit but use "git diff" to see what changed)

Notice: src/index.js is listed as modified. Git sees the change but hasn't saved a snapshot yet.


Step 9: Stage Your Changes

Staging is the first step to committing. It says, "I'm ready to save these files."

$ git add src/index.js
$ git status

Expected output:

On branch main

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
    modified:   src/index.js

Notice the wording changed from "not staged" to "to be committed." That's the staged state.


Step 10: Make Your First Commit

$ git commit -m "Add multiply function to math utils"

If git asks for your name or email, set them once and retry the commit:

$ git config --global user.name "Your Name"
$ git config --global user.email "you@example.com"

Expected output:

[main abc1234] Add multiply function to math utils
 1 file changed, 3 insertions(+)

The hash (abc1234 in this example) uniquely identifies this snapshot. Your actual hash will be different.

Now check status:

$ git status

Expected output:

On branch main
nothing to commit, working tree clean

Perfect! You're back to a clean state. Your change is now saved.


Step 11: View Your Commit History

See all commits made to this repo:

$ git log --oneline

Expected output (varies based on repo history):

abc1234 Add multiply function to math utils
def5678 Initial commit

The most recent commit is at the top. You can see a short hash, branch, and message.


Step 12: Try One More Commit (Optional)

Go ahead and add another function or fix a comment. Then:

$ git add src/index.js
$ git commit -m "Add comments to functions"
$ git log --oneline

The more you practice, the more comfortable you'll be.


Troubleshooting

Problem Solution
"git: command not found" Install git. See Prerequisites.
"fatal: not a git repository" Make sure you're in the cloned folder. Run pwd to confirm.
"nothing to commit" You haven't made any changes. Edit a file and try again.
Accidentally committed something Don't panic. You'll learn to undo commits in Module 3. For now, ask your instructor.

What You've Done

✓ Opened the terminal and navigated folders with cd, pwd, ls. ✓ Cloned a local starter repository with git clone. ✓ Read file contents with cat. ✓ Checked git status with git status. ✓ Made a change and staged it with git add. ✓ Saved a snapshot with git commit. ✓ Viewed history with git log.

These are the foundational skills you'll use every day with OpenCode.


Reflection

Before moving on, answer these in your own words:

  1. What does git status tell you? Why is it useful?
  2. What's the difference between git add and git commit?
  3. Why does git use messages on commits? (What's in the message for?)
  4. If you made a mistake in a file but haven't committed yet, how would you see the exact changes you made? (Hint: git diff)

Next Steps

  • Move to Lab 2: Prompting to learn how to write good prompts.
  • In Module 2, we'll use these skills with OpenCode to automate changes.