What would I use git-worktree for?

前端 未结 10 1180
不知归路
不知归路 2020-11-27 10:18

I read Github\'s post on git-worktree. They write:

Suppose you\'re working in a Git repository on a branch called feature, when a user re

10条回答
  •  难免孤独
    2020-11-27 10:32

    tl;dr: Any time you want to have two work trees checked out at the same time for whatever reason, git-worktree is a quick and space-efficient way to do it.

    If you create another worktree, most parts of the repo (i.e. .git) will be shared, meaning if you create a branch or fetch data while you are in one work tree, it will also be accessible from any other work trees you have. Say you want to run your test suite on branch foo without having to push it somewhere to clone it, and you want to avoid the hassle of cloning your repo locally, using git-worktree is a nice way to create just a new checkout of some state in a separate place, either temporarily or permanently. Just like with a clone, all you need to do when you are done with it is delete it, and the reference to it will be garbage collected after some time.

提交回复
热议问题