1 of 30

Lecture 3:

Bash Recap + Intro to Version Control

Fall 2025

2 of 30

Announcements

  1. Lab 1 due tomorrow at midnight
  2. Labs 2 and 3 will be on version control. We’re going to “go deep” on the kinds of things you can do with distributed version control.
    • It’s tricky, so make some time for it!

3 of 30

Outline

  1. Bash activity (review from Thursday)
  2. Coding Review (containsPair + URL Shortener)
  3. Discussion of the Readings
  4. Intro to git & GitHub

4 of 30

Outline

  1. Bash activity (review from Thursday)
  2. Coding Review (containsPair + URL Shortener)
  3. Discussion of the Readings
  4. Intro to git & GitHub

5 of 30

Shell / Bash Review

  • What is a shell?
    • cat /etc/shells
    • echo $SHELL
  • How do you configure your shell?
  • For Windows users: why did we make you install and use WSL (versus using DOS / PowerShell)?
  • What is your home directory and what can you find there?
  • How do you install new programs from the command line?

6 of 30

Editing your .zshrc or .bashrc file

  1. What is the purpose of your .zshrc (or .bashrc)?
  2. In lab 1, you made / are making a shortcut. What other edits do you think you might be able to add to your .zshrc file?��Try this one:��today() �{ � echo This is a `date +"%A %d in %B of %Y (%r)"`.�}
  3. What does the “source” command do?

7 of 30

Exercise 1: Common Bash Commands

Let’s try doing these exercises together (Windows users: please use WSL + Ubuntu):�

Using the Command Line Cheat Sheet

  1. How do you figure out what directory you’re in?
  2. How do you list all of the files in your current directory?
  3. How do you look at directories and subdirectories in a “tree-like” structure?
  4. How do you list hidden files?
  5. How do you read the contents of a file?
  6. How do you display your command line history?
  7. How do you search your Desktop for any file with the string “csci” in it?

8 of 30

Answers Exercise 1: (Try it before you look)...

  1. How do you figure out what directory you’re in?
  2. How do you list all of the files in your current directory?
  3. Listing directories and subdirectories?
  4. How do you list hidden files?
  5. How do you read the contents of a file?
  6. How do you display your command line history?
  7. How do you search your Desktop for any file with the string “csci” in it?

9 of 30

Answers Exercise 1: (Try it before you look)...

  • How do you figure out what directory you’re in?
    • pwd
  • How do you list all of the files in your current directory?
    • ls or ls -l
  • Listing directories and subdirectories?
    • tree -L 2 # where the number corresponds to levels of nesting
  • How do you list hidden files?
    • ls -a or ls -la
  • How do you read the contents of a file?
    • cat my_file.txt
  • How do you display your command line history?
    • history
  • How do you search your Desktop for any file with the string “csci” in it?
    • grep 'csci' ~/Desktop -r

10 of 30

Exercise: Bash + VIM Practice

Open a terminal

For Windows: Activate WSL using the command prompt PowerShell

Open a file called init-app.sh using nano

Command: vi init-app.sh

Create a script that:

  1. Makes a new directory called my-app
  2. Creates two empty files inside of my-app:
    • index.html
    • style.css

Use the course command line cheat sheet to help you. Hints:

  • mkdir
  • touch

Save your file and exit

Ctrl+O – Saves changes�Crtl+X – Exit editor

Test the bash script you just made:

bash init-app.sh

11 of 30

Answers: Bash + VIM Practice

cd ~/Desktop/csci338 # should be a different path for you

echo "Hello world!" > readme.txt

cat readme.txt # should print "Hello world!" to the screen

vi init-app.sh

Within vim, go into edit mode by pressing the i key.

Then add the following lines to test.sh:

mkdir my-app

touch my-app/index.html

touch my-app/style.css

Save and quit vim by first pressing the Escape key and � then typing :wq to save and quit

bash init-app.sh # should have created a my-app directory + HTML/CSS file within your current directory

12 of 30

Outline

  1. Bash activity (review from Thursday)
  2. Coding Review (containsPair + URL Shortener)
  3. Discussion of the Readings
  4. Intro to git & GitHub

13 of 30

Reminder of the Problem

Write a function – using any programming language you want – that takes in a list of integers. The function returns true if the list contains two or more of the same integer, false otherwise.

// Java

public static boolean containsPair(List<Integer> l) {

return false;

}

14 of 30

Suggested Approach

  1. Come up with some sample lists of when the function should return true and when it should return false.
    1. Where the duplicates are… in order, out of order, towards the beginning, towards the end, etc.
  2. Consider edge cases:
    • Does your code work with an empty array or with an array with only one Integer?

Also: You probably won’t be allowed to use a code editor when you’re doing coding interviews. Whiteboarding only!

15 of 30

containsPair: Approach #1

public static boolean containsPair(List<Integer> l) {

for (int i = 0; i < l.size() - 1; i++) {

if (l.get(i).equals(l.get(i + 1))) {

return true;

}

}

return false;

}

Q: Does this work? If not, what is the problem? Can you think of a scenario where this could work and a code enhancement you might make?

16 of 30

containsPair: Approach #2

public static boolean containsPair(List<Integer> l) {

for (int i = 0; i < (l.size() - 1); i++) {

for (int j = i + 1; j < l.size(); j++) {

if (l.get(i).equals(l.get(j))) {

return true;

}

}

}

return false;

}

Q: Does this work? Is it efficient? What’s the worst case scenario?

17 of 30

containsPair: Approach #2 with bug

public static boolean containsPair(List<Integer> l) {

for (int i = 0; i < (l.size() - 1); i++) {

for (int j = 0; j < l.size(); j++) {

if (l.get(i).equals(l.get(j))) {

return true;

}

}

}

return false;

}

Q: Can you find the bug? Why is it a bug?

18 of 30

containsPair: Approach #3

public static boolean containsPair(List<Integer> l) {

List<Integer> unique = new ArrayList<Integer>();

for (int i = 0; i < l.size(); i++) {

if (unique.contains(l.get(i))) {

return true;

}

unique.add(l.get(i));

}

return false;

}

Q: Does this work? Is it efficient? What’s the worst case scenario?

19 of 30

containsPair: Approach #4

public static boolean containsPair(List<Integer> l) {

Map<Integer, Integer> s = new HashMap<Integer, Integer>();

for(int i = 0; i < l.size(); i++) {

if (s.containsKey(l.get(i))) {

return true;

}

s.put(l.get(i), 1);

}

return false;

}

Q: Does this work? Is it efficient? Do you think this is different than approach 3? Why or why not? What’s the worst case scenario?

20 of 30

containsPair: Approach #5

public static boolean containsPair(List<Integer> l) {

Set<Integer> s = new HashSet<Integer>(l);

return s.size() != l.size();

}

Q: Does this work? Is it efficient? What’s the worst case scenario?

21 of 30

Good Work!

Thinking like this takes lots of practice. Keep at it. We’ll keep doing these problems all semester.

22 of 30

URL Shortener

Your boss asks you to implement a URL shortener. Specifically:

  1. A user types a long URL into a textbox (e.g., https://docs.google.com/document/d/1lb4iE41b-aJoR9B3M007bYTT-m3p9E8D/edit)
  2. The system gives the user back a shortened URL (e.g., https://t.ly/e8vxn)
  3. Thereafter, if anyone clicks the shortened url, the page redirects to the original (long) URL.

What steps would you take to implement this system?

Let’s draw this out on the whiteboard…

23 of 30

Outline

  1. Bash activity (review from Thursday)
  2. Coding Review (containsPair + URL Shortener)
  3. Discussion of the Readings
  4. Intro to git & GitHub

24 of 30

Why is Code History important?

  • Seeing what you wrote before – if something blows up, you want to be able to revert
  • What changes have been made over time and who made them
  • Getting an old version to run

25 of 30

Why is Version Control Important?

26 of 30

What is the difference between centralized and distributed version control?

  • Centralized: One server that has the history
  • Distributed: Git

27 of 30

What is the problem with having long-running dev branches? What is the solution?

28 of 30

What is the one version rule?

29 of 30

What are the tradeoffs of having a Monorepo versus multiple repos?

Pros of Monorepos:

  • Your thoughts here

Cons of Monorepos:

  • Your thoughts here

30 of 30

What files do you check into version control? What files do you NOT check in?

  • Yes:
    • Source code

  • No:
    • Binaries
    • Api keys
    • Passwords