0
0
Gitdevops~5 mins

Removing worktrees in Git - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a Git worktree?
A Git worktree is an additional working directory linked to the same Git repository, allowing you to work on multiple branches simultaneously without switching branches in one directory.
Click to reveal answer
beginner
How do you list all existing Git worktrees?
Use the command git worktree list to see all worktrees connected to your repository.
Click to reveal answer
beginner
What is the command to remove a Git worktree safely?
Use git worktree remove <path> to safely remove a worktree at the specified path. This deletes the worktree directory and unregisters it from Git.
Click to reveal answer
intermediate
What happens if you manually delete a Git worktree directory without using Git commands?
Manually deleting the directory leaves Git unaware of the removal, causing git worktree list to still show it. This can cause confusion or errors later.
Click to reveal answer
intermediate
Why should you use git worktree remove instead of just deleting the folder?
Because git worktree remove cleans up Git's internal records and safely deletes the worktree folder, preventing stale references and potential repository issues.
Click to reveal answer
Which command lists all Git worktrees?
Agit worktree list
Bgit worktree show
Cgit list worktrees
Dgit worktree status
What does git worktree remove <path> do?
ARemoves the worktree directory and unregisters it from Git
BOnly deletes the worktree directory but keeps Git records
CSwitches the current branch to the worktree branch
DCreates a new worktree at the given path
What risk comes from deleting a worktree folder manually?
AGit will create a new worktree automatically
BThe repository will be deleted
CBranches will be merged automatically
DGit still thinks the worktree exists, causing stale references
Can you remove the main worktree with git worktree remove?
AYes, but only if you are on the master branch
BNo, the main worktree cannot be removed this way
CYes, it removes the main worktree safely
DNo, you must delete it manually
What is the first step before removing a worktree?
ASwitch to the main branch in the worktree
BDelete the .git folder inside the worktree
CMake sure no processes are using the worktree directory
DRun git fetch
Explain how to safely remove a Git worktree and why it is important.
Think about what happens inside Git when you remove a worktree.
You got /4 concepts.
    Describe what a Git worktree is and how it helps in working with branches.
    Imagine having multiple folders for different tasks in the same project.
    You got /4 concepts.