>_ IzzyLab

Hands-on task

This task is step 19 of the course “Git: rewriting and rescuing history”

Add a working tree for a branch

medium~5 min

In /root/repo there is a main branch (the current one) and a release branch, which contains a file rel.txt that's absent in main.

Without switching the current branch, add a separate working tree for the release branch in the directory /root/wt. After that, /root/wt should contain the contents of the release branch (including rel.txt), and the directory itself should be registered as a working tree of this repository with the release branch checked out.

What you'll practise:
  • git worktree
  • working trees
  • branches
  • parallel work

Topic breakdown

A single repository (the .git folder) can serve several independent working directories at once — each with its own checked-out branch. This is handy when you need to keep several branches "open" simultaneously without switching back and forth with git checkout and without losing uncommitted changes. The key limitation of the mechanism: the same branch can't be kept checked out in two places at once. The list of registered trees is shown by git worktree list.

What's checked

  1. the contents of release are checked out in /root/wt
  2. the directory is registered as a worktree
  3. the release branch is checked out in the worktree

What it looks like