Two people, one file
Sam and Aisha both change the same file. Sam saves at 10:00. Aisha saves at 10:05. Sam's work is gone.
Teams solve this with version control. Version control is a tool that keeps every version and joins changes safely. Even when you work alone, it protects you.
Key words
| Word | What it means | Example |
|---|---|---|
| Version control | A tool that keeps every saved version of your work. | Git |
| Repository | A folder that holds your project and its history. | hillside-tool |
| Commit | A saved step in the history, with a short message. | Add leave_waiting_list |
| Branch | A separate line of work that you join back later. | waiting-list |
| Pull request | A request to join your branch into the main one, so others can review it. | Add the waiting list |
| Code review | Another person reads your code and gives feedback. | a checklist |
| Pair programming | Two people work at one computer. One types and one watches. | one person types, one person checks |
| Merge | Join the work of a branch into the main version. | join waiting-list into main |
| Function | A named piece of code that does one job. | next_in_line() |
| Readability | How easy the code is for a person to read. | clear names |
The cells students fill in are left blank in this preview.
Match the word to its meaning
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
The Git commands in this lesson
| Command | What it does |
|---|---|
| cd hillside-tool | Goes into the folder |
| echo "text" > waiting.py | Makes a file called waiting.py with that text in it |
| git init hillside-tool | Makes a new repository in a folder called hillside-tool |
| git status | Shows which files changed |
| git add waiting.py | Chooses a file for the next commit |
| git config --global user.name "Student" | Tells Git your name, so each commit shows who made it |
| git config --global user.email "[email protected]" | Tells Git your email, so each commit shows who made it |
| git commit -m "message" | Saves a step with a short message |
| git log --oneline | Shows the history, one line each |
| git checkout -b waiting-list | Makes a new branch and moves to it |
The cells students fill in are left blank in this preview.
Start the lab first
Note
Press Start the lab on the bar at the top of this lesson. Wait until it says it is running. Each Run button types a command into your lab terminal. The commands work in a new practice folder, so nothing important can break. Never run a command you do not understand.
Step 1: make a repository
git init hillside-toolA command for the lesson’s lab terminal. It is shown here and not run.
Step 2: go into the folder
cd hillside-toolA command for the lesson’s lab terminal. It is shown here and not run.
Step 3: make a file
echo "# Hillside waiting list" > waiting.pyA command for the lesson’s lab terminal. It is shown here and not run.
Step 4: ask Git what it sees
git statusA command for the lesson’s lab terminal. It is shown here and not run.
What did you see?
Have a go
What did you see?
3 questionsStep 5: choose the file
git add waiting.pyA command for the lesson’s lab terminal. It is shown here and not run.
Step 6: tell Git your name
git config --global user.name "Student"A command for the lesson’s lab terminal. It is shown here and not run.
Step 7: tell Git your email
git config --global user.email "[email protected]"A command for the lesson’s lab terminal. It is shown here and not run.
Step 8: save a step
git commit -m "Add the waiting list file"A command for the lesson’s lab terminal. It is shown here and not run.
Step 9: read the history
git log --onelineA command for the lesson’s lab terminal. It is shown here and not run.
What did you see?
Have a go
What did you see?
3 questionsStep 10: start a branch
git checkout -b waiting-listA command for the lesson’s lab terminal. It is shown here and not run.
From a branch to the main version
flowchart LR
main[Main version] --> branch[Make a branch]
branch --> work[Work and commit]
work --> pr[Pull request]
pr --> review{Review: any problems?}
review -->|yes| work
review -->|no| merge[Join into main]
Check: version control
Have a go
Check: version control
4 questionsTask 2 practice: build the waiting list
Task 2 practice. Build two more waiting list functions. join_waiting_list is finished. next_in_line gives the first member waiting for a court and hour, or None. leave_waiting_list removes a member and gives back True or False. Commit after each function if you use Git. Press Run Tests to check your work.
def join_waiting_list(waiting, member, court, hour):
# Finished for you. waiting is a list of dictionaries.
place = 0
for one in waiting:
if one["court"] == court and one["hour"] == hour:
if one["member"] == member:
return 0
place = place + 1
waiting.append({"member": member, "court": court, "hour": hour})
return place + 1
def next_in_line(waiting, court, hour):
# Give back the name of the first member waiting for this court and hour.
# Give back None if nobody is waiting for it.
return 0
def leave_waiting_list(waiting, member, court, hour):
# Remove this member's entry for this court and hour.
# Give back True if it was removed, False if it was not there.
return None
Make a free account to save your work, or press Start lab to work through the whole lesson.
Three ways to review code
| Way | What happens | How formal |
|---|---|---|
| Pair programming | Two people work at one computer. One types, one watches and thinks. | Very informal |
| Informal walkthrough | You show your code to a teammate and explain it line by line. | Informal |
| Formal inspection | A planned meeting with set roles. The faults are written down. | Formal |
The cells students fill in are left blank in this preview.
A kind and useful code review
| Look for | Say it like this |
|---|---|
| A name that is unclear | I did not understand what x means. Could it be called place? |
| A missing check | What happens when the list is empty? Maybe add a test. |
| Good work | The function does one job and is easy to read. Well done. |
| A repeated block | These two parts look the same. Could one function do both? |
The cells students fill in are left blank in this preview.
Talk about the code, not the person
Tip
Say "this line" and not "you". Be exact. Give one good point and one improvement. When you get feedback, say thanks, ask if you do not understand and decide what to change.
Task 2 practice: commits and a review
Part A: write four commit messages for the four steps of building the waiting list: start the file, then add join_waiting_list, next_in_line and leave_waiting_list. Each should say what was added, in one short line. Part B: read the function leave_waiting_list that you wrote. Write a short code review of it as if you were a teammate: one good point, one thing to improve and one question. Part C: write two sentences about how you would act on feedback from a teammate.
A teacher marks this in a college. Nothing you write here is kept: it goes when you leave the page.
Make a free account to save your work, or press Start lab to work through the whole lesson.
Key words crossword
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Final check
Have a go