Skip to content

Lab 1.1: Terminal & Git Basics

Goal

Set up your terminal environment, clone a starter repo, 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 WSL coming in Week 2)
  • Internet connection to clone the 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 (Week 2). For now, follow the macOS instructions once you have WSL installed, or adapt the commands to PowerShell (most work the same).


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 all your course work in one place. Let's create it.

$ cd ~
$ mkdir opencode-course
$ cd opencode-course
$ pwd

Expected output:

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


Step 3: Clone the Starter Repo

We've prepared a starter repo with a simple Node.js project. Clone it:

$ git clone https://github.com/opencode/week1-starter.git
$ cd week1-starter
$ ls

Expected output (contents of the cloned folder):

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

If you see these files, the clone succeeded.

Troubleshooting: - "git: command not found" — git is not installed. See Prerequisites above. - "fatal: unable to access repository" — Check your internet connection, or the URL may be wrong. Ask your instructor.


Step 4: Explore the Repo Structure

Let's get comfortable navigating:

$ pwd

Expected output:

/Users/yourname/opencode-course/week1-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 ..
-rw-r--r--   1 yourname  staff   215 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):

# Week 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
Your branch is up to date with 'origin/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. You can use any text editor (VS Code, nano, vim, etc.). For this example, we'll use echo and file redirection:

$ echo "" >> src/index.js
$ echo "function multiply(a, b) {" >> src/index.js
$ echo "  return a * b;" >> src/index.js
$ echo "}" >> src/index.js
$ echo "module.exports = { add, multiply };" > src/index.js.tmp && mv src/index.js.tmp src/index.js

Or, if you prefer, open the file in VS Code:

$ code src/index.js

And manually add:

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

Then change the export line to:

module.exports = { add, multiply };


Step 8: Check Status Again

$ git status

Expected output:

On branch main
Your branch is up to date with 'origin/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
Your branch is up to date with 'origin/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"

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
Your branch is up to date with 'origin/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 Week 3. For now, ask your instructor.

What You've Done

✓ Opened the terminal and navigated folders with cd, pwd, ls. ✓ Cloned a remote git 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 1.2: Prompting to learn how to write good prompts.
  • In Week 2, we'll use these skills with OpenCode to automate changes.