Forrest logo
back to the git tool

git-worktree:tldr:27256

git-worktree: Create a new directory with the specified branch checked out into it.
$ git worktree add ${path-to-directory} ${branch}
try on your machine

The "git worktree add" command is used to create a new working tree for a specific branch. This feature was introduced in Git version 2.5 to let users work on multiple branches at the same time without needing to switch back and forth.

Here's the breakdown of the command:

  • "git worktree add": This is the main command to add a new working tree.
  • "${path-to-directory}": This is the path where you want to create the new working tree. It can be an existing or new directory.
  • "${branch}": This is the branch you want to associate with the new working tree. It can be an existing branch or a new branch that will be created.

When you run this command, Git will create a new directory at the specified path and populate it with all the necessary files and references for the given branch. You can then switch to that directory and work on the branch independently, without affecting the other working trees or repositories.

This command is particularly useful in scenarios where you need to work on multiple features or bug fixes simultaneously, or when you want to preview changes before merging them into a stable branch. It allows for better organization and easier context-switching between different branches without any interference.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the git tool