What would I use git-worktree for?

前端 未结 10 1125
不知归路
不知归路 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:39

    For me, git worktree is the biggest improvement since a long time. I'm working in enterprise software development. There, it is very common that you have to maintain old versions like what you released 3 years ago. Of course you have a branch for each version so that you can easily switch to it and fix a bug. However, switching is expensive, because in the meantime you completely restructured the repository and maybe build system. If you switch, your IDE will run mad trying to adapt the project settings.

    With worktree, you can avoid that constant reconfiguration. Checkout those old branches in separate folders using worktree. For each branch, you got an independent IDE project.

    Of course this could have been done in the past by cloning the repo several times and this has been my approach so far. However, that also meant wasting hardrive space and worse needing to fetching the same changes from the repo several times.

    0 讨论(0)
  • 2020-11-27 10:39

    I originally stumbled on this question after wondering what these fancy worktrees could be used for. Since then I have integrated them into my workflow and in spite of my initial scepticism I have come to find them quite useful.

    I work on a rather large code-base, which takes quite some time to compile. I usually have the current development branch on my machine along with the feature branch I am currently working on plus the master branch, which represents the current state of the live system.

    One of the biggest benefits for me is obviously that I don't have to recompile the entire thing everytime I switch branches (that is, worktrees). A nice side-effect is that I can go to the development worktree, do stuff there, change directory to the worktree for my current feature branch and then rebase it without having to pull first.

    0 讨论(0)
  • 2020-11-27 10:45

    I'm using git worktree for machine learning development.

    I have a main functional code and then I want to split branches of different experiments (different algorithms and different hyperparameters). git worktree allows me to integrate dvc alongside different versions of my code specialized to different algorithms. After running all training jobs I evaluate final metrics and merge to master the best branch/model.

    0 讨论(0)
  • 2020-11-27 10:46

    I can see some uses for this.

    If you have a test suite that runs for a long time, imagine hours, and you start it it effectively blocks that working copy until the tests are completed. Switching branches during those tests would break them in ways that would be hard to understand.

    So with git-worktree I could have a second idea launched for another branch doing work there.

    Also, when I switch to some other branch to do some quick investigation my IDE thinks a lot of files suddenly changed and will index all those changes, just to have to re-index them again when I'm switching back.

    A third use case would be to do file comparison using other tools than git-diff, like normal diff, between two directories instead if two branches.

    0 讨论(0)
提交回复
热议问题