Branches and merging

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

Branches and merging

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which command creates a new branch called login-form?
A git merge login-form
B git branch login-form
2. What is the purpose of a branch?
A A separate line of development you can work on safely
B A backup copy that can never be changed
3. Which command switches you onto the branch login-form?
A git checkout login-form
B git branch -m login-form
4. You finished a feature on login-form. To combine it into main, which steps are correct?
A git checkout login-form, then git merge main
B git checkout main, then git merge login-form
5. What is a merge conflict?
A Two branches changed the same lines, so Git cannot combine them automatically
B A branch has been deleted from the repository by mistake

Match the Pairs

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

Left columnRight column
1git branch login-page Agit checkout login-page
2git merge login-page BThis is a merge conflict. Both branches changed the same line, so Git cannot choose one. The markers must be removed and one version kept before committing.
3Switch to a branch so your new commits are added to that line of development instead of main. CCreates a new branch called login-page, a separate line of development, without changing the main branch.
4To combine a finished feature branch into main, first switch to main and then run the merge command. Dgit checkout main git merge login-page
5git checkout main git merge main EMerging main into itself does nothing. The name after git merge should be the feature branch whose changes you want to bring into main.
6<<<<<<< HEAD score = 10 ======= score = 20 >>>>>>> login-page FCombines the changes from the login-page branch into the branch you are currently on, such as main.

Definitions

git branch

Fill in the Blanks

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

1.
git ______ login-form
2.
git ________ login-form
3.
git checkout main git _____ login-form
4.
git checkout ____ git merge login-form
5.
CONFLICT (content): Merge ________ in app.py

Spot the Error

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

Question 1
A git branch login
B git checkout login
C git comit -am "Add login"
Question 2
A git new-branch feature-menu
B git checkout feature-menu
C git commit -am "Add menu"
Question 3
A git checkout main
B git merge dark-mode
C git branch -b dark-mode
Question 4
A git branch report
B git checkout main
C git add report.py
D git commit -m "Add report"
Question 5
A git checkout main
B git merge main
C git branch -d search

Answer Key

Branches and merging
Section A: Quick Questions
Q1
B — git branch login-form
Q2
A — A separate line of development you can work on safely
Q3
A — git checkout login-form
Q4
B — git checkout main, then git merge login-form
Q5
A — Two branches changed the same lines, so Git cannot combine them automatically
Section B: Match the Pairs
Q1
git branch login-page → Creates a new branch called login-page, a separate line of development, without changing the main branch.
Q2
git merge login-page → Combines the changes from the login-page branch into the branch you are currently on, such as main.
Q3
Switch to a branch so your new commits are added to that line of development instead of main. → git checkout login-page
Q4
To combine a finished feature branch into main, first switch to main and then run the merge command. → git checkout main git merge login-page
Q5
git checkout main git merge main → Merging main into itself does nothing. The name after git merge should be the feature branch whose changes you want to bring into main.
Q6
<<<<<<< HEAD score = 10 ======= score = 20 >>>>>>> login-page → This is a merge conflict. Both branches changed the same line, so Git cannot choose one. The markers must be removed and one version kept before committing.
Section C: Definitions
Q1
git branch — Creates a branch, a separate line of development that you work on safely and later combine into the main branch with git merge.
Section D: Fill in the Blanks
Q1
git branch login-form
Q2
git checkout login-form
Q3
git checkout main git merge login-form
Q4
git checkout main git merge login-form
Q5
CONFLICT (content): Merge conflict in app.py
Section E: Spot the Error
Q1
C — The command is misspelled. It should be git commit, which saves the changes on the login branch.
Q2
A — git new-branch is not a Git command. A branch is created with git branch feature-menu.
Q3
C — -b is not a valid option for git branch. Use -d to delete a branch once it has been merged into main.
Q4
B — This keeps the student on main, so the report work would be committed to main instead of the new branch. It should be git checkout report.
Q5
B — You are already on main, so this does not bring in the search work. The branch to combine must be named: git merge search.