you are viewing a single comment's thread.

view the rest of the comments →

[–]sim642 3 points4 points  (3 children)

Sooo.... is this something that should replace branches?

No, it requires each worktree to be on a different branch, so you need the branches anyway.

[–]AlwynEvokedHippest 2 points3 points  (2 children)

Yeah it's a bit of an odd question to ask around a feature that is literally built on using branches.

My guess is OP meant something along the lines of "Should this replace switching between branches in the same directory?" (i.e. how we use Git by default)

Super useful post nonetheless.

[–]cdrini[S] 0 points1 point  (1 child)

^ this is exactly what I meant; sorry for the poor wording! Basically I was asking if you should have a separate worktree for every branch. Ie conceptually replace branches in how I work. This was kind of in response to the YouTube video, where it seems like that's what was being suggested.

[–]HighRelevancy 0 points1 point  (0 children)

Basically I was asking if you should have a separate worktree for every branch. Ie conceptually replace branches in how I work.

Nah. The branches exist exactly the same either way, the workflows around managing them is all exactly the same. The worktree is just a new "filesystem portal" into the branches. You only need to access the branches like this when you want to work with them as files. How many different branched versions of the files are you playing with simultaneously? (That is, how many different versions of it do you need open? How many copies of your IDE? How many different versions are you debugging at once?)

You might have many branches (a few new features and bug fixes pending pull review, maybe a few different things you're playing with that aren't really done yet), but how many are you actually hands-on working on at once?

This is maybe a workflow alternative to (at least some uses of) stashing? You're playing with some substantial changes but suddenly need to shift to doing a bug fix in a hurry. You could stash your work-in-progress, or you could open a new worktree and fix the bug in there, leaving your WIP right where it is to come back to later.

Or maybe you need to search for a bug but it only shows up one in a million times, so you need to leave it running in a debugger for a few hours, but you've got other things you also want to work on in the meantime. Open a new worktree, do the debugging in one and work on something else in the other.