CodeBlanks Logo Icon CodeBlanks

Summary - Worktree

Combine worktree commands to set up parallel branch work.

Parallel Work with Worktrees

git worktree lets you work in parallel on different branches using multiple working directories in the same repository. git worktree add creates a new worktree, while git worktree list displays existing worktrees. This allows you to fix a bug in one branch while developing a feature in another.

git worktree add ../feature feature
git worktree list

Practice Set Up a Parallel Worktree Workflow

First, define a command that adds a new worktree for the review branch at ../review. Then create a second command that lists the worktrees. Print both commands in order using console.log.

Starter code

terminal
// Yeni çalışma ağacını ekleyen komut
const addCommand = "";

// Çalışma ağaçlarını listeleyen komut
const listCommand = "";

// Komutları sırayla yazdır

Sample solution

terminal
const addCommand = "git worktree add ../review review";
const listCommand = "git worktree list";
console.log(addCommand);
console.log(listCommand);

Expected output

git worktree add ../review review
git worktree list

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which command sequence is suitable for working on a feature branch in a separate directory?

  • git worktree add feature followed by git commit
  • git worktree add ../feature feature followed by git worktree list Correct answer
  • git worktree list followed by git status
  • git worktree remove ../feature followed by git worktree list

Explanation: First, use <code>add</code> to create the new directory and branch association, then use <code>list</code> to inspect the worktrees.

2 Complete the Parallel Work Commands

Question
git worktree ____ ../review review
git worktree 
Answer
git worktree add ../review review
git worktree 

Explanation: The first command uses add to place the review branch in a separate directory. The second command must use list to display the worktrees.

3 Worktree Workflow

Term Meaning
git worktree Working tree management
add Adding a new directory
list Displaying worktrees
Paralel çalışma Using different branches simultaneously

All lessons in Advanced