[00:00] Git-worktree, which you already have installed if you have git, allows you to add a branch with "-b". And we'll call this branch full-path, just follow your team's naming schemes for branches. And then a directory where you want this work tree to be added. So we'll go up a directory, then slash, then the name of our current project, which is fileForge, and then dash full-path. So once I hit enter here, it's created this new branch, checked everything out, and if I run cursor and go up a directory and then over up to fileForge dash full-path and hit enter, You'll see I have a brand new instance of cursor running, and if I make a change to like the readme or some minor change, let's say contributing, sounds great, we can just undo this later.
[00:45] But when I commit the changes here we'll add this and generate a message and commit. Oh I forgot this will run my pre-commit hooks, so I do need to at least install the required packages so that the pre-commit hooks can run and run the tests. And that's just happening behind the scenes right now. So all the tests pass behind the scenes and the commit was successful. We can hop back over to our main branch.
[01:08] We can say git merge, and then merge in the full path branch. Let me show you the readme so that when you see the before and after. So I'll hit enter. There's no contributing. And after I get this contributing section in.
[01:22] And you'll see with our git status, we have one commit we need to push to our remote. So at this point we can git worktree remove, and then go up the directory, and then pass in our file forge full path, hit enter. And that cleaned up. If I try and swap back over to this project you'll see all the files are deleted and there's nothing in here because all the work here is done. So to start multiple composer sessions working on different branches I'll show you this function in zshrc.
[01:52] I called it wtree and this will be shared below. Once you invoke wtree you can pass in as many branches as you want to create. If you pass in the P flag it'll automatically use PMPM to install dependencies. You'd have to configure this based on the projects you're working on. And then once everything is set up it's going to fire off cursor to open each project.
[02:13] So let's say in my scenario I want to work on that full path feature and I want to work on a few variations of it. So I'll just say A, B, and C, and then with dash P it'll install all the packages. So once I hit enter here it's going to create all those work trees, install all the packages, launch cursor for each of them, and then I have these three separate branches with three separate workspaces where I can experiment with Composer working on the same thing in three different ways. And I'll just create a new space for each of these so if I'll grab A I can drop it here, B drop it here, C drop it over here, So I can essentially check in on them as they're working through the issues. Then open Composer, give it a task.
[02:56] I'll just give it my source, my test directory, then tell it to please implement a feature where if a user passes in the full path to a file it can also be included within the final digest that's output. Hit enter and then you can go over and either work on the same task or work on a separate task, then get multiple composers all running at the same time. And you can come in and check on them, see if you like the results. If you're working with different web servers, you'd want to give each one a different port so you could check that on different browsers. And I've set it up in my workflow where I also have this merge function.
[03:32] So I'm going to W merge or WT merge and this is going to allow me to pick the branch that I think won rather than manually merging in each one. It's going to pick the one that I think was best. We'll say that it was full path A. Hit enter and that's going to bring in all the changes from full path A. Looks like there is some undefined things we need to fix up first.
[03:54] So let's go into fixtures, dir, accept all, open our problems, we'll attempt to fix with AI. Hit accept here, then go back and try and run this again. So we'll merge in fullPathA, so it's bringing in all those changes, and then because it's committing it's running all my tests I always run my tests on commit. Then it looks like the feature that we added wasn't fully fixed. I don't know why I expected Composer to be able to one-shot this, but I'll start a new Composer, I'll switch to agent mode, paste in the issues, I'll say run pnpm test, attempt to fix all of the failing tests, Hit enter.
[04:30] All right for the sake of the video I was trying to have Composer fix this. I'm just going to unstage and revert all my changes. This was a much more complicated task than a one sentence description. I could have made a plan and all the standard practices for working on more complicated tasks. For now, I'm just going to remove this part of the readme we made before.
[04:51] Then once I go back over, I'll run my WT merge full path again. So now all the tests pass and you can see that it's committing our changes, bringing everything in, and it's deleting all the branches, deleting all the work trees. So if we check our other spaces here you'll see that this path A is gone, path B is gone, path C is gone. We could have had all of these working on different tasks and this WTMerge function is for picking out the specific one, the one that you like the best. And you can see we now have the changes where it removed what we added to the readme.
[05:25] So I'll share these functions below. You could definitely do these manually or ask the AI to do this sort of stuff for you, but to be very aware once you use these I did hard code the parent directory for all of my projects. So mine will put it in the home dev directory. You could ask AI to add a flagged configure where you want that to be or just hardcode yours. And I do have WT merge only support keeping one branch and then deleting the rest.
[05:52] If you want a different behavior please ask an AI to work on that for you. It's fairly simple logic for it to handle. But you could also just go through all the manual steps of get work tree add, get work tree remove, get merge branch in, and all the manual steps that that would take as well.