0
0
Gitdevops~20 mins

Creating a worktree in Git - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Worktree Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of creating a new worktree
What is the output of the following command if the branch feature-x does not exist yet?

git worktree add ../feature-x feature-x
Git
git worktree add ../feature-x feature-x
Aerror: pathspec 'feature-x' did not match any file(s) known to git
Bfatal: 'feature-x' is not a commit and a branch 'feature-x' cannot be created from it.
C
Preparing worktree (detached HEAD) in ../feature-x
Branch 'feature-x' set up to track remote branch 'feature-x' from 'origin'.
D
Preparing worktree in ../feature-x
Switched to a new branch 'feature-x'
Attempts:
2 left
💡 Hint
The command creates a new branch and a new worktree directory.
🧠 Conceptual
intermediate
1:30remaining
Purpose of git worktree
Which of the following best describes the purpose of using git worktree?
ATo create multiple working directories linked to the same repository, allowing simultaneous work on different branches.
BTo permanently delete branches from the repository history.
CTo clone a repository into a new directory with a different remote URL.
DTo merge two branches automatically without conflicts.
Attempts:
2 left
💡 Hint
Think about working on multiple features at the same time.
Troubleshoot
advanced
2:00remaining
Error when adding a worktree
You run the command git worktree add ../test-branch origin/test-branch but get the error:

fatal: 'origin/test-branch' is not a commit and a branch 'origin/test-branch' cannot be created from it.

What is the most likely cause?
AThe directory '../test-branch' already exists and is not empty.
BThe remote branch 'test-branch' does not exist locally or remotely, so git cannot create a worktree from it.
CYou do not have permission to create directories in the parent folder.
DThe git repository is corrupted and needs to be reinitialized.
Attempts:
2 left
💡 Hint
Check if the remote branch exists before adding a worktree.
🔀 Workflow
advanced
2:30remaining
Steps to remove a worktree safely
Which sequence of commands correctly removes a git worktree located at ../feature-y and cleans up references?
A1,3,4
B2,3,4
C1,4,3
D3,1,4
Attempts:
2 left
💡 Hint
Use git commands to remove worktree and branch, then prune.
Best Practice
expert
3:00remaining
Best practice for concurrent feature development
You want to work on two features simultaneously without switching branches in the same directory. Which is the best practice using git worktree?
AClone the repository twice into different folders and work on each feature separately.
BUse <code>git stash</code> to save changes and switch branches in the same directory repeatedly.
CCreate two separate worktrees, each checked out to a different feature branch, so you can work independently.
DCommit all changes to the main branch and then create feature branches later.
Attempts:
2 left
💡 Hint
Think about avoiding switching branches in one folder.