A Git worktree is an additional working directory linked to the same Git repository. It allows you to work on multiple branches simultaneously without switching branches in a single directory.
Click to reveal answer
beginner
How do you create a new worktree for a branch named feature?
Use the command git worktree add <path> feature. This creates a new directory at <path> with the feature branch checked out.
Click to reveal answer
intermediate
Why use Git worktrees instead of cloning the repository multiple times?
Worktrees share the same Git repository data, saving disk space and keeping history consistent. Cloning multiple times duplicates data and uses more space.
Click to reveal answer
beginner
What command lists all existing Git worktrees?
Run git worktree list to see all worktrees linked to the repository, including their paths and checked-out branches.
Click to reveal answer
intermediate
How do you remove a Git worktree safely?
First, delete the worktree directory manually. Then run git worktree prune to clean up references to removed worktrees.
Click to reveal answer
What does the command git worktree add ./new-feature feature do?
ACreates a new directory ./new-feature with the branch 'feature' checked out
BDeletes the branch 'feature'
CSwitches the current directory to branch 'feature'
DClones the repository into ./new-feature
✗ Incorrect
The command adds a new worktree at ./new-feature with the 'feature' branch checked out.
Which command shows all worktrees linked to your Git repository?
Agit status
Bgit branch -a
Cgit remote -v
Dgit worktree list
✗ Incorrect
git worktree list displays all worktrees connected to the repository.
Why might you prefer a Git worktree over cloning the repo multiple times?
AWorktrees save disk space by sharing repository data
BWorktrees create separate repositories
CCloning is faster than worktrees
DWorktrees do not support multiple branches
✗ Incorrect
Worktrees share the same Git data, saving disk space compared to multiple clones.
What must you do after deleting a worktree directory manually?
ARun <code>git branch -d</code>
BRun <code>git clone</code>
CRun <code>git worktree prune</code> to clean references
DNothing, Git cleans automatically
✗ Incorrect
After manual deletion, git worktree prune removes stale references.
Can you have multiple worktrees checked out on different branches at the same time?
ANo, only one worktree can be active
BYes, that is the main benefit of worktrees
CYes, but only if branches are merged
DNo, worktrees share the same branch
✗ Incorrect
Worktrees let you work on multiple branches simultaneously in separate directories.
Explain what a Git worktree is and why it is useful.
Think about working on two projects at once without switching folders.
You got /3 concepts.
Describe the steps to create and then remove a Git worktree safely.
Consider how to add a new folder for a branch and clean up after.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of creating a Git worktree?
easy
A. To work on multiple branches simultaneously in separate folders
B. To merge two branches automatically
C. To delete a branch safely
D. To compress the repository size
Solution
Step 1: Understand what a worktree is
A Git worktree allows you to have multiple working directories linked to the same repository.
Step 2: Identify the main use case
This lets you work on different branches at the same time without switching branches in one folder.
Final Answer:
To work on multiple branches simultaneously in separate folders -> Option A
git worktree add ../test-branch test
cd ../test-branch
git branch --show-current
What will be the output of the last command?
medium
A. master
B. main
C. test
D. detached HEAD
Solution
Step 1: Understand what 'git worktree add' does
This command creates a new folder with the specified branch checked out.
Step 2: Check current branch in new worktree
After changing directory, git branch --show-current shows the branch name checked out, which is 'test'.
Final Answer:
test -> Option C
Quick Check:
Worktree folder shows branch name = test [OK]
Hint: Worktree folder shows the branch you added [OK]
Common Mistakes:
Assuming default branch 'main' or 'master'
Thinking it shows detached HEAD
Confusing branch names
4. You run git worktree add ../new-feature without specifying a branch. What will happen?
medium
A. Git creates a new worktree with the current branch checked out
B. Git creates a new branch automatically
C. Git throws an error asking for a branch name
D. Git creates a detached HEAD worktree at the current commit
Solution
Step 1: Check behavior when branch is omitted
If no branch is specified, Git creates a worktree at the current commit in detached HEAD state.
Step 2: Understand the result
This means the worktree is not on any branch but on a specific commit.
Final Answer:
Git creates a detached HEAD worktree at the current commit -> Option D
Quick Check:
No branch given = detached HEAD worktree [OK]
Hint: No branch? Worktree is detached HEAD at current commit [OK]
Common Mistakes:
Expecting an error without branch
Thinking it uses current branch name
Assuming a new branch is created
5. You want to work on two branches, main and feature, simultaneously. Your repo has no feature branch yet. Which sequence correctly creates a worktree for feature and switches to it?
hard
A. git worktree add ../feature feature
cd ../feature
B. git branch feature
git worktree add ../feature feature
cd ../feature
C. git worktree add ../feature feature
cd ../feature
git checkout -b feature
D. git checkout -b feature
git worktree add ../feature feature
cd ../feature
Solution
Step 1: Create the branch before adding worktree
You must create the branch 'feature' first because it does not exist yet.
Step 2: Add the worktree for the new branch and switch directory
Then add the worktree pointing to 'feature' and change to that folder.
Final Answer:
git branch feature
git worktree add ../feature feature
cd ../feature -> Option B
Quick Check:
Create branch first, then add worktree [OK]
Hint: Create branch first, then add worktree for it [OK]
Common Mistakes:
Adding worktree before branch exists
Creating branch inside worktree folder
Forgetting to switch directory
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.