0
0
Gitdevops~10 mins

Listing worktrees in Git - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Listing worktrees
Run 'git worktree list'
Git reads .git/worktrees directory
Git gathers info on each worktree
Git outputs list with paths and HEAD info
Display result
The command reads the worktrees info and shows a list of all linked worktrees with their paths and current branch or commit.
Execution Sample
Git
git worktree list
Lists all worktrees linked to the current repository with their paths and HEAD states.
Process Table
StepActionGit Internal ProcessOutput
1User runs 'git worktree list'Git starts reading worktree info
2Git reads .git/worktrees directoryFinds all linked worktrees
3Git reads HEAD info for each worktreeGets current branch or commit for each
4Git formats list outputPrepares path and HEAD info lines
5Git prints list to terminalOutput shows each worktree path and HEAD/path/to/main-worktree 123abc [main] /path/to/feature-worktree 456def [feature-branch]
6Command endsAll worktrees listedDone
💡 All linked worktrees have been listed with their paths and HEAD states.
Status Tracker
VariableStartAfter Step 2After Step 3Final
worktrees_listemptypaths of all worktrees foundpaths + HEAD info for each worktreecomplete list with paths and HEAD info
Key Moments - 2 Insights
Why does the output show commit hashes and branch names?
Because git reads the HEAD of each worktree to show what commit or branch it currently points to, as seen in execution_table step 3 and 5.
What if I have no extra worktrees created?
The list will show only the main worktree path and its HEAD info, or just one entry, as git always includes the main worktree.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table step 5 output, what does '[feature-branch]' represent?
AThe current branch checked out in that worktree
BThe remote repository URL
CThe last commit message
DThe worktree creation date
💡 Hint
Refer to execution_table step 3 and 5 where HEAD info is read and displayed.
At which step does git gather the commit hashes for each worktree?
AStep 1
BStep 3
CStep 2
DStep 5
💡 Hint
Check execution_table where HEAD info is read for each worktree.
If you create a new worktree, how will the variable 'worktrees_list' change after step 2?
AIt will include commit hashes
BIt will remain empty
CIt will include the new worktree path
DIt will be deleted
💡 Hint
See variable_tracker after step 2 where paths of all worktrees are found.
Concept Snapshot
git worktree list
- Lists all worktrees linked to the repo
- Shows path and current HEAD (branch or commit)
- Reads .git/worktrees directory
- Useful to see multiple working copies
- Output includes main and extra worktrees
Full Transcript
The 'git worktree list' command shows all worktrees connected to your git repository. When you run it, git reads the .git/worktrees directory to find all linked worktrees. Then it reads the HEAD information for each worktree to find out which branch or commit is currently checked out. Finally, it prints a list showing each worktree's path and its HEAD state. This helps you see all your working copies and their current branches or commits at a glance.