Code repositories

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Code repositories

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does a code repository store?
A The project's source code and its full version history
B Only the final compiled program that users run
2. What is a commit?
A A saved snapshot of changes, recorded with a message and author
B A copy of the repository made private to one developer
3. Why would a developer create a branch?
A To delete the version history and start again
B To work on a feature or fix without changing the main code
4. What happens when a branch is merged?
A Its changes are combined into another branch, such as main
B The branch is encrypted and locked from all developers
5. What is the main security benefit of a pull request?
A Changes are merged instantly without anyone checking them
B Teammates can review changes before they are merged

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1git commit -m "Fix login check" APushing straight to the main branch skips peer review, so insecure or faulty code can enter the project unchecked. Work should be done on a branch and merged through a pull request.
2git merge feature-login BCombines the changes from the feature-login branch into the branch you are currently on
3A pull request lets teammates review a branch's changes before they are merged into the main branch CSaves a snapshot of the changes into the repository's version history with a message describing what changed
4A private repository restricts who can see and change the project's source code, which protects confidential code DA commit without a clear message makes the repository's version history hard to read and audit. The message should describe what changed and why, e.g. "Add input validation to login form".
5git commit -m "" (committing with no message, or with a vague one like "stuff") Egh repo create payroll-app --private
6git push origin main (pushing directly to main with no pull request or review) Fgh pr create --base main --head feature-login

Definitions

code repository

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
git ______ -m "Add login form"
2.
git ______ feature-login
3.
git _____ feature-login
4.
gh __ create --title "Add login form"
5.
gh repo create secure-app --_______

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A git init
B git adds main.py
C git commit -m "Add login"
Question 2
A git checkout -b feature-login
B git add login.py
C git commit "Add login form"
Question 3
A git checkout main
B git pull
C git merge main
Question 4
A git clone https://git.io/app
B cd app
C git checkout fix-bug
D git push origin fix-bug
Question 5
A git pull origin feature-nav
B Open a pull request on main
C Teammate reviews the changes
D Merge the pull request

Answer Key

Code repositories
Section A: Quick Questions
Q1
A — The project's source code and its full version history
Q2
A — A saved snapshot of changes, recorded with a message and author
Q3
B — To work on a feature or fix without changing the main code
Q4
A — Its changes are combined into another branch, such as main
Q5
B — Teammates can review changes before they are merged
Section B: Match the Pairs
Q1
git commit -m "Fix login check" → Saves a snapshot of the changes into the repository's version history with a message describing what changed
Q2
git merge feature-login → Combines the changes from the feature-login branch into the branch you are currently on
Q3
A pull request lets teammates review a branch's changes before they are merged into the main branch → gh pr create --base main --head feature-login
Q4
A private repository restricts who can see and change the project's source code, which protects confidential code → gh repo create payroll-app --private
Q5
git commit -m "" (committing with no message, or with a vague one like "stuff") → A commit without a clear message makes the repository's version history hard to read and audit. The message should describe what changed and why, e.g. "Add input validation to login form".
Q6
git push origin main (pushing directly to main with no pull request or review) → Pushing straight to the main branch skips peer review, so insecure or faulty code can enter the project unchecked. Work should be done on a branch and merged through a pull request.
Section C: Definitions
Q1
code repository — A central store for a project's source code and its version history, shared by a team through commits, branches, pull requests and access settings (private or public).
Section D: Fill in the Blanks
Q1
git commit -m "Add login form"
Q2
git branch feature-login
Q3
git merge feature-login
Q4
gh pr create --title "Add login form"
Q5
gh repo create secure-app --private
Section E: Spot the Error
Q1
B — There is no 'adds' command. The staging command is 'git add main.py', which prepares the file for the next commit to the repository.
Q2
C — The commit message must follow the -m flag. It should be: git commit -m "Add login form".
Q3
C — Merging main while on main does nothing. To bring the branch's commits in, it should be 'git merge feature-login'.
Q4
C — Without -b, Git tries to switch to a branch that doesn't exist yet. Creating a new branch needs 'git checkout -b fix-bug'.
Q5
A — A pull request needs the branch on the shared repository. You must push the branch with 'git push origin feature-nav', not pull it.