We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Linked Worktrees

We've talked about:

  1. Stash (temporary storage for changes)
  2. Branches (parallel lines of development)
  3. Clone (copying an entire repo)

Worktrees accomplish a similar goal (allow you to work on different changes without losing work), but are particularly useful when:

  1. You want to switch back and forth between the two change sets without having to run a bunch of git commands (not branches or stash)
  2. You want to keep a light footprint on your machine that's still connected to the main repo (not clone)

The Main Worktree

  • Contains the .git directory with the entire state of the repo
  • Heavy (lots of data in there!). To get a new main working tree requires a git clone or git init

A Linked Worktree

  • Contains a .git file with a path to the main working tree
  • Light (essentially no data in there!), about as light as a branch
  • Can be complicated to work with when it comes to env files and secrets

Create a Linked Worktree

To create a new worktree at a given path:

git worktree add <path> [<branch>]

Adding <branch> is optional. It will use the last part of the path as the branch name.

Assignment

Run and submit the CLI tests from the root of the main working tree (megacorp).