Tuesday, May 31, 2022

git- work tree

 A Git worktree is a linked copy of your Git repository, allowing you to have multiple branches checked out at a time. A worktree has a separate path from your main working copy, but it can be in a different state and on a different branch.

Imagine you have multiple branches and want to work on them all simultaneously. Normally you’d be forced to constantly switch back and forth, shelving and stashing any changes you would commit. But there’s an easier way. Just set up multiple git working trees.

For example, imagine that you initialized a git repository and created three git flow branches: fix, feature and release.

/example/git worktree add (master)

  • $ git branch fix
  • $ git branch feature
  • $ git branch release

A developer can set up multiple git working trees with the ‘git worktree add’ command, with the name of the subfolder and the name of the branch specified as options. The git worktree syntax is:

git worktree add -path- -branch-

/example/git worktree add (master)

  • $ git worktree add hotfix fix
  • $ git worktree add latest release
  • $ git worktree add new-feature feature


Post a Comment