A Git worktree is an additional working directory linked to the same Git repository, allowing you to check out different branches simultaneously without cloning the repo again.
Click to reveal answer
beginner
How do Git worktrees help with parallel work?
Git worktrees let you work on multiple branches at the same time in separate folders, so you can develop features or fix bugs without switching branches in one directory.
Click to reveal answer
beginner
What command creates a new Git worktree?
The command is git worktree add <path> <branch>. It creates a new directory at <path> with the specified branch checked out.
Click to reveal answer
intermediate
Why is using Git worktrees better than cloning the repo multiple times for parallel work?
Worktrees share the same Git data, saving disk space and keeping history consistent, unlike multiple clones which duplicate data and can get out of sync.
Click to reveal answer
beginner
Can you commit changes independently in each Git worktree?
Yes, each worktree acts like a separate workspace where you can make commits independently on different branches without affecting others.
Click to reveal answer
What does a Git worktree allow you to do?
AWork on multiple branches at the same time in different directories
BClone the repository multiple times
CMerge branches automatically
DDelete branches remotely
✗ Incorrect
Git worktrees let you have multiple working directories for different branches without cloning the repo.
Which command creates a new Git worktree?
Agit checkout <branch>
Bgit clone <repo>
Cgit branch -d <branch>
Dgit worktree add <path> <branch>
✗ Incorrect
The 'git worktree add' command creates a new working directory linked to the repo.
Why are Git worktrees more efficient than multiple clones?
AThey automatically merge branches
BThey require internet access
CThey share the same Git data, saving disk space
DThey delete old branches
✗ Incorrect
Worktrees share the Git repository data, so they use less disk space than multiple clones.
Can you commit changes independently in each Git worktree?
AOnly if branches are merged
BYes, each worktree is a separate workspace
CNo, commits affect all worktrees
DOnly on the main branch
✗ Incorrect
Each worktree lets you commit changes independently on its checked-out branch.
What problem does using Git worktrees solve?
ASwitching branches without losing work or needing multiple clones
BAutomatically resolving merge conflicts
CBacking up repositories online
DDeleting remote branches
✗ Incorrect
Worktrees let you work on different branches in parallel without switching or cloning repeatedly.
Explain how Git worktrees enable you to work on multiple branches at the same time.
Think about having separate folders for each branch.
You got /4 concepts.
Describe the benefits of using Git worktrees compared to cloning the repository multiple times.
Consider efficiency and data sharing.
You got /4 concepts.
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
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.
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.
Final Answer:
It allows working on multiple branches simultaneously in separate folders. -> Option C
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
Step 1: Recall correct syntax for adding a worktree
The correct syntax is git worktree add <path> <branch>.
Step 2: Match options to syntax
Only git worktree add ../feature feature matches this syntax exactly. Others use wrong commands or order.
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
Step 1: Understand what git worktree add ../feature feature does
This creates a new folder ../feature checked out to the feature branch.
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.
Final Answer:
On branch feature, with changes from that branch. -> Option D
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
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.
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.
Final Answer:
The branch 'feature' does not exist in the repo. -> Option A
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: