3 ms·
Offtopic, but I often wonder if there are people using `git worktree` to have several related code trees within the same repo. Technically it works the mostly
by tuyiown 6y ago
Offtopic, but I often wonder if there are people using `git worktree` to have several related code trees within the same repo.
Technically it works the mostly the same as multiple repos, but theoretically allows to have something like a bootstrap script with everything self contained in the same repos. Looks like an alternative tradeoff between a monorepos with shared history and multiple repositories.
- pjc50 6y agoI tried that, and discovered that it won't let you have two worktrees with the same branch checked out?
- hiq 6y agoOfftopic (I think), but I just learned that "For instance, git worktree add -d <path> creates a new working tree with a detached HEAD at the same commit as the current branch." (from the manpage). It's offtopic because the second worktree has a detached HEAD, so that doesn't help in the case you mention.
- ivanbakel 6y agoWhich is very sane - what should git do if you modify the branch in one tree but not in the other? The least painful solution would require something like multiple-refs-per-remote-branch, which would be (to my understanding) a re-architecture.
- pjc50 6y agoWell, I wanted the same effect as two separate checkouts (ie entirely separate branch structures) but with a bit of the disk space shared between them, but that's not how it works.
- alblue 6y agoYou can use “git clone” for that; it will set up an alternates link in the local clone, so you only store the git object data in the origin but apply deltas to the clone.
- hiq 6y agoDo you have an example of this setup? As far as I know git worktree is just to have different branches of the same repo checked out in different locations. At least, that's the only way I use it (and it's great!). Are you suggesting to have different projects on different branches? So an empty "master", then "project1", "project2" etc. as branches?
- numbsafari 6y agoI'm not sure worktree works exactly as you think. I use worktree locally so that, for example, I can have my working copy that I am doing development in and then a separate working copy where I can do code review for someone else, without having to interrupt what I am doing in my own worktree. My own experience is that if you are using branches with radically different content for different purposes in the same tree, it's going to end up a mess at some point. Worktrees, as far as I am aware, do not help with that in any special way.
- oftenwrong 6y agoAre you thinking of git subtree? https://www.atlassian.com/git/tutorials/git-subtree https://www.atlassian.com/git/tutorials/git-subtree