Bird
Raised Fist0
Gitdevops~20 mins

Why worktrees enable parallel work in Git - Challenge Your Understanding

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Git Worktree Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
How do Git worktrees help with parallel development?

Git worktrees allow you to have multiple working directories linked to the same repository. What is the main advantage of using worktrees for parallel work?

AThey let you work on different branches simultaneously without switching branches in one directory.
BThey automatically merge branches when you switch between them.
CThey create separate repositories on your disk for each branch.
DThey prevent you from committing changes until all branches are synchronized.
Attempts:
2 left
💡 Hint

Think about how switching branches normally affects your working directory.

💻 Command Output
intermediate
2:00remaining
Output of listing Git worktrees

What is the output of the command git worktree list after adding a new worktree for branch feature?

Git
git worktree add ../feature feature
git worktree list
A
/path/to/repo feature
/path/to/feature feature
B
/path/to/repo HEAD
/path/to/feature feature
C
/path/to/repo master
/path/to/feature feature
D
/path/to/repo master
/path/to/feature master
Attempts:
2 left
💡 Hint

Remember the main repository's current branch and the new worktree's branch.

🔀 Workflow
advanced
3:00remaining
Steps to create and use a Git worktree for parallel feature development

Arrange the steps in the correct order to create a new Git worktree for a feature branch and start working on it.

A2,1,3,4
B1,2,3,4
C1,3,2,4
D1,2,4,3
Attempts:
2 left
💡 Hint

Create the branch first, then add the worktree, then move into it, then check status.

❓ Troubleshoot
advanced
2:00remaining
Error when adding a Git worktree for an existing branch

You run git worktree add ../feature feature but get an error: fatal: 'feature' already checked out at '../feature'. What is the cause?

AYou do not have permission to create directories outside the current folder.
BThe main repository is in a detached HEAD state.
CThe branch 'feature' does not exist in the repository.
DThe branch 'feature' is already checked out in another worktree at '../feature'.
Attempts:
2 left
💡 Hint

Check if the branch is already checked out somewhere else.

✅ Best Practice
expert
3:00remaining
Why prefer Git worktrees over cloning for parallel work?

Which is the best reason to use Git worktrees instead of cloning the repository multiple times for parallel development?

AWorktrees share the same .git data, saving disk space and keeping history consistent.
BWorktrees automatically sync changes between branches without manual merges.
CWorktrees create isolated repositories that do not share any data.
DWorktrees allow pushing to remote repositories without authentication.
Attempts:
2 left
💡 Hint

Think about disk space and repository data duplication.

Practice

(1/5)
1. What is the main benefit of using git worktree for parallel work?
easy
A. It deletes old branches to save space.
B. It automatically merges branches without conflicts.
C. It allows working on multiple branches simultaneously in separate folders.
D. It creates a backup of the entire repository.

Solution

  1. Step 1: Understand what git worktree does

    git worktree lets you check out multiple branches at once in different folders without cloning the repo multiple times.
  2. Step 2: Compare options with this feature

    Only It allows working on multiple branches simultaneously in separate folders. correctly describes this benefit. Other options describe unrelated or incorrect features.
  3. Final Answer:

    It allows working on multiple branches simultaneously in separate folders. -> Option C
  4. Quick Check:

    Parallel branch work = It allows working on multiple branches simultaneously in separate folders. [OK]
Hint: Worktrees = multiple branches in separate folders [OK]
Common Mistakes:
  • Thinking worktrees merge branches automatically
  • Confusing worktrees with backups
  • Assuming worktrees delete branches
2. Which command correctly creates a new worktree for branch feature in folder ../feature?
easy
A. git worktree create feature ../feature
B. git worktree add ../feature feature
C. git add worktree ../feature feature
D. git checkout worktree feature ../feature

Solution

  1. Step 1: Recall correct syntax for adding a worktree

    The correct syntax is git worktree add <path> <branch>.
  2. Step 2: Match options to syntax

    Only git worktree add ../feature feature matches this syntax exactly. Others use wrong commands or order.
  3. Final Answer:

    git worktree add ../feature feature -> Option B
  4. Quick Check:

    Correct add syntax = git worktree add ../feature feature [OK]
Hint: Use 'git worktree add <path> <branch>' to create worktree [OK]
Common Mistakes:
  • Using 'create' instead of 'add'
  • Mixing order of arguments
  • Using 'git add' or 'git checkout' incorrectly
3. Given these commands executed in a repo:
git worktree add ../feature feature
cd ../feature
git status

What will git status show in the ../feature folder?
medium
A. On branch master, with changes from master branch.
B. Error: not a git repository.
C. Detached HEAD state with no branch.
D. On branch feature, with changes from that branch.

Solution

  1. Step 1: Understand what git worktree add ../feature feature does

    This creates a new folder ../feature checked out to the feature branch.
  2. Step 2: Check git status in that folder

    Since the folder is a valid worktree on feature branch, git status shows branch feature and its changes.
  3. Final Answer:

    On branch feature, with changes from that branch. -> Option D
  4. Quick Check:

    Worktree folder branch = feature [OK]
Hint: Worktree folder tracks specified branch, not master [OK]
Common Mistakes:
  • Assuming worktree defaults to master branch
  • Thinking worktree folder is detached HEAD
  • Confusing worktree folder with unrelated repo
4. You ran git worktree add ../dev feature but got an error: fatal: 'feature' is not a commit and a branch 'feature' cannot be created from it. What is the likely cause?
medium
A. The branch 'feature' does not exist in the repo.
B. The folder '../dev' already contains a git repo.
C. You forgot to commit changes before adding worktree.
D. You used 'git worktree create' instead of 'add'.

Solution

  1. Step 1: Analyze the error message

    The error says 'feature' is not a commit and branch cannot be created, meaning the branch does not exist.
  2. Step 2: Match cause to options

    The branch 'feature' does not exist in the repo. matches this cause. Other options describe unrelated issues or wrong commands.
  3. Final Answer:

    The branch 'feature' does not exist in the repo. -> Option A
  4. Quick Check:

    Branch must exist before adding worktree [OK]
Hint: Check branch exists before adding worktree [OK]
Common Mistakes:
  • Assuming folder conflict causes this error
  • Thinking uncommitted changes block worktree add
  • Confusing 'add' with 'create' command
5. You want to work on two features in parallel without cloning the repo twice. You create two worktrees:
git worktree add ../feature1 feature1
git worktree add ../feature2 feature2

What is a key advantage of this approach compared to cloning twice?
hard
A. It saves disk space by sharing the same .git data.
B. It automatically syncs changes between branches.
C. It prevents any merge conflicts between branches.
D. It allows pushing both branches with one command.

Solution

  1. Step 1: Understand difference between worktrees and cloning

    Worktrees share the same repository data (.git) but have separate working folders, saving disk space.
  2. Step 2: Evaluate options

    It saves disk space by sharing the same .git data. correctly states the disk space saving. Other options describe features not provided by worktrees.
  3. Final Answer:

    It saves disk space by sharing the same .git data. -> Option A
  4. Quick Check:

    Worktrees share repo data, saving space [OK]
Hint: Worktrees share .git data, saving space vs cloning [OK]
Common Mistakes:
  • Thinking worktrees auto-sync branches
  • Assuming worktrees prevent merge conflicts
  • Believing one push updates multiple branches
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard