What is worktree
The worktree feature is used to manage multiple working trees. Implementation of worktree feature provide us to checkout multiple branches at the same time. Worktree gives a extra working copy of the repository. The new worktree is also known as Linked working tree. The worktree is not only for the branches, but with the help of worktree we can check out tags of different worktree.
When we have multiple working trees branches and we want to work on both simultaneously then we stash our work and checkout from current branch , test and go back. And if we want to check again, we do it again. Instead we create a worktree with their branch and now we just need to change directory and look at their work and come back and resume our work.
Git worktree add :
Work tree add command creates work tree where new working tree is linked with the current repository by sharing everything except working directory like HEAD, index ,etc.
Git worktree list :
Work tree list used for listing details of each working tree and main working tree is listed first and followed by each of the linked working trees.
Git work tree lock and remove :
Worktree command comes in Git v2.10 . This also used to prevents it from being remove or deleted. After write the command we can write (–reason) this contains simple text specify a reason for lock.
Git remove command used for remove the work tree . The main working tree cannot be removed in a multi module project we are working then if we want to check all the branches without using the stash feature this feature is best alternative many developer who are using git this feature is very helpful .