This site is under construction. All dates and policies are tentative until this message goes away.

Homework 1: Setup

In CS 61B, we write code using real-world industry tools, and you’ll install those tools in this assignment.

Tools Overview: Terminal

There’s nothing to do in this section; you just need to read through it carefully. The actual tasks start at Task 1.

In CS 61B, we will use the terminal to run various commands.

When you work in a terminal, the terminal always has a working directory, which is the folder that the terminal is currently thinking about.

  • The ls command lists all of the files in the working directory.
  • The pwd command prints out the working directory.
  • The cd command changes the working directory.

Many terminal commands behave differently depending on your working directory, so it is very important to ensure you are in the correct working directory before running a command! Remember, you can use pwd to check the working directory.

Further reading: Terminal guide

Tools Overview: Git

There’s nothing to do in this section; you just need to read through it carefully. The actual tasks start at Task 1.

Almost all computer scientists use Git when writing code. Git lets you take snapshots of different versions of your code (useful if you want to revert to an earlier version). Here’s a demo video:

Git also lets you sync a repository (a folder containing your code) on different computers. For example, you and your partner will use Git in later projects to work together.

One common place to sync code is GitHub. You can think of GitHub as a really big computer on the cloud, and everybody can sync their code to this computer (e.g. to save a backup copy, or to share the code with the world).

Git is very complicated, but there are a few core commands you should know for CS 61B.

  • To copy a repo from GitHub to your computer (creating a new folder on your computer), use this command:
    git clone git@github.com:oski/name-of-oskis-repo.git
    
  • To sync code from a repo on your computer, to a repo on GitHub, use these three commands:
    # First, take a snapshot of your code. (The commit message is mandatory!)
    git add .
    git commit -m "your commit message here"
    
    # Then, send your snapshot from your computer to GitHub.
    git push origin main
    
  • To retrieve updates from a repo on GitHub, to a repo on your computer, use this command:
    git pull skeleton main
    

This diagram shows the repositories we use in CS 61B, and the commands you can use to sync code between them. (Click to enlarge.)

Git push and pull diagram

Further reading: Git guide

That’s it for the overview. Now, let’s start setting up your computer!

  • If something isn’t working, do not try random things you find online. Ask a TA for help.
  • Everyone should complete this lab on their own computer (no partners).
  • Do not skip steps, or else you will run into errors later.

Task 1: Install Git

Click your operating system to see instructions.

macOS

  1.  xcode-select --install
    

    This might take some time.

    If you see “Command line tools are already installed,” move on to the next step (and make sure you see the version number in the next step).

  2.  git --version
    

    You should see a version number like git version 2.51.0 (a different number is fine) and no errors.

Windows

  1. Windows Download Git

  2. We’ll only be selecting different options on the Select Components page, where we add a Git bash profile to the windows terminal.

    Add git bash profile

    All the other options should be left as is. The entire install process is shown in the gif below:

    Windows git install

  3. Terminal app in the start menu

    Older Windows versions may not have the Terminal app pre-installed. If you can’t find Terminal, install it from the Microsoft Store.

  4. Terminal Setup 1

  5. Terminal Setup 2

  6. Git Bash Setup Correctly

Linux

  1.  sudo apt install git curl
    

    For other Linux distributions, you might need to replace apt install with yum install or something else.

  2.  git --version
    

    You should see a version number like git version 2.51.0 (a different number is fine) and no errors.

Task 2: Create GitHub repository

  1. If you already have an account, you do not need to create a new one.

  2. This email will be sent to the email that you used to create your GitHub account, which may not necessarily be your Berkeley email.

  3. If you do not see a number (e.g. it says None), please click the Redo Registration button. If that fails, please make a post on Ed.

Task 3: Set Up Git

  1.  git config --global user.name "oski"
     git config --global user.email "oski@berkeley.edu"
    
  2.  git config --global init.defaultBranch main
     git config --global pull.rebase false
     git config --global core.editor "nano -w"
    

Task 4: Authenticate to GitHub

  1.  curl -sS --ssl-no-revoke https://fa25.datastructur.es/assets/homeworks/hw01/get-ssh-key.sh | bash 
    

    In the output, you should see a line similar to one of these:

     Great! Your new SSH key is at: ~/.ssh/id_ed25519.pub
     You already have an SSH key at: ~/.ssh/id_ed25519.pub
    
  2.  cat ~/.ssh/id_ed25519.pub
    

    You should see output similar to this:

     ssh-ed25519 AAAAC3NzaC1lZDI1N6jpH3Bnbebi7Xz7wMr20LxZCKi3U8UQTE5AAAAIBTc2HwlbOi8T oski@oski
    
  3. Go to GitHub’s SSH settings page and paste the output in the Key box.

    The title can be anything you want (e.g. “Laptop” or “Desktop” if you have multiple computers). Leave “Key type” as “Authentication Key.” Click “Add SSH key” to add the key.

    If you are retaking the class, you might see “Key is already in use.” If so, move on to the next step (and make sure you see the success message in the next step).

  4.  ssh -T git@github.com
    

    If the system asks “The key is not know by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])?”, type “yes”.

    If you see output like this, you’re done with this step:

     Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.
    

    If you don’t see this output, redo the steps in this section. If it still doesn’t work after redoing the steps, ask TAs for help.

Task 5: Cloning Repositories

When you work in a terminal, the terminal always has a working directory, which is the folder that the terminal is currently thinking about.

  • The cd command can be used to change the working directory.
  • The pwd command can be used to print out the working directory.

Many terminal commands behave differently depending on your working directory. In this task, it is very important to ensure you are in the correct working directory before running a command.

For example, the command touch potato.txt creates a new file potato.txt in the working directory. If you run this command while in the wrong directory, you’d create the file in the wrong folder!

  1. The cs61b folder can live anywhere, but we recommend putting it on your Desktop so that you don’t lose it.

  2.  cd ~/Desktop/cs61b
    

    If you’re not sure how to use cd, read this terminal guide.

  3.  pwd
    

    The output should end in cs61b (e.g. /home/oski/Desktop/cs61b). This means that your terminal’s working directory is the cs61b folder.

  4.  pwd   # make sure this outputs a path ending in cs61b
     git clone git@github.com:Berkeley-CS61B/library-fa25.git
    

    If the command worked, your cs61b folder should now have a sub-folder named library-fa25 in it. You can check this by running ls in the terminal, or opening a file explorer.

  5.  ls library-fa25
    

    This command lists the content of the library-fa25 folder. The output should have some lines like this:

     algs4.jar
     animated-gif-lib-1.4.jar
     antlr4-runtime-4.11.1.jar
     apiguardian-api-1.1.2.jar
    
  6.  pwd   # make sure this outputs a path ending in cs61b
     git clone git@github.com:Berkeley-CS61B-Student/fa25-s12345.git
    

    If the command worked, your cs61b folder should now have a sub-folder named something like fa25-s12345. You can check this by running ls in the terminal, or opening a file explorer.

    Do not run a git clone command multiple times. It will create multiple copies of the same folder on your computer, and this will cause trouble later.

    If you think you messed up this step, use a file explorer to search for folders on your computer named fa25-s12345. You should only have a single one!

    If you see a message like “warning: You appear to have cloned an empty repository,” it is safe to ignore.

  7.  cd fa25-s12345
    
  8.  git remote add skeleton git@github.com:Berkeley-CS61B/skeleton-fa25.git
    

    If you see a message like “fatal: not a git repository,” make sure you did the previous step.

  9.  git remote -v
    

    Make sure you see 4 lines of output like this:

     origin      git@github.com:Berkeley-CS61B-Student/fa25-s12345.git (fetch)
     origin      git@github.com:Berkeley-CS61B-Student/fa25-s12345.git (push)
     skeleton    git@github.com:Berkeley-CS61B/skeleton-fa25.git (fetch)
     skeleton    git@github.com:Berkeley-CS61B/skeleton-fa25.git (push)
    
  10.  git pull skeleton main
    

    If the command worked, your fa25-s12345 folder should now have a sub-folder named hw01 in it. You can check this by running ls in the terminal, or opening a file explorer.

    If you see “fatal: refusing to merge unrelated histories,” try running git pull skeleton main --allow-unrelated-histories --no-rebase instead.

  11.  git branch -M main
    
  12.  cs61b
     ├── library-fa25
     │   ├── algs4.jar
     │   ├── animated-gif-lib-1.4.jar
     │   ├── antlr4-runtime-4.11.1.jar
     │   ├── apiguardian-api-1.1.2.jar
     │   └── ...
     ├── fa25-s12345
     │   ├── hw01
     │   │   ├── src
     │   │   │   └── Arithmetic.java
     │   │   ├── tests
     │   │   │   └── ArithmeticTest.java
    

Task 6: Set up IntelliJ

  1. Also, ensure you have at least 2 GB of free RAM (i.e. close other programs you don’t need).

  2. You have to scroll down to find the Community Edition.

    IntelliJ Community Edition

    For macOS users: If you have an M1, M2, M3 Mac, select “.dmg (Apple Silicon).” Otherwise, select “.dmg (Intel).”

  3. On the window that appears, click “Marketplace” and enter “CS 61B” in the search bar at the top. The CS 61B plugin entry should appear.

    Install 61B Plugin

    If you have the plugin installed from a prior term, make sure to update it.

  4. Install Java Visualizer Plugin

Task 7: Install Java

  1. Open IntelliJ

  2. Do not choose the entire fa25-12345 folder. We want the hw01 sub-folder specifically.

    Open Folder

  3. If you see 21 in the SDK drop-down, simply select 21.

    If you do not see 21 in the SDK drop-down, click “Download JDK” to download Microsoft OpenJDK 21.

    Download JDK

    JDK Version

  4. Select JDK

Task 8: Write code in IntelliJ

  1. For the rest of the semester, every time you open an assignment, you have to follow those steps again. (Sorry, we know it’s tedious.)

    Add libraries step 1

    Add libraries step 2

    Add libraries step 3

  2. Arithmetic IntelliJ

  3. Arithmetic run main

    If you get an error like package edu.princeton.cs.algs4 does not exist, make sure you followed the Assignment Workflow Guide in Step 1 of this task!

  4. Arithmetic prompt

    If you follow the prompts, you will probably see that the math is wrong! Don’t fix it yet.

  5. arithmetic run test

    arithmetic test failed

    We can see that “Test product correctness” passed, but “Test sum correctness” failed.

Task 9: Submitting your work

  1.  git status
    

    The output will tell you if you have any unsynced changes:

    git status

    This means your edit to Arithmetic.java is on your local computer, but not on GitHub.

  2.  git add hw01/src/Arithmetic.java
     git commit -m "fixed Arithmetic.java in hw01"
     git push origin main
    

    For future assignments, you can replace hw01/src/Arithmetic.java in the first command to add other files. You can also replace the message in quotes in the second command to describe your changes.

  3. You can also open https://github.com/Berkeley-CS61B-Student/fa25-s12345, and you should see your changes synced on GitHub!

  4. Select GitHub, then your fa25-s12345 repository and the main branch, and submit your assignment.

    If you don’t see the repository, you may need to link your GitHub account to Gradescope.

  5. Congratulations on finishing the homework!

Appendix: Common Issues

Q: How do I set up a second computer or a new computer?

Setting up a second computer requires redoing Tasks 1, 3, 4, 5, 6, 7 on your second computer.

You would need to keep the two repos on the two computers in sync by running git push origin main on computer 1 (to send updates from computer 1 to GitHub), and git pull origin main on computer 2 (to download the updates from GitHub).