2 points
*

I commit and squash before pushing the branch if I have to change what I’m working on. Keeps the changes on remote so I don’t lose progress. Not like a PR is open if the work I isn’t ready anyway.

permalink
report
reply
3 points

I guess I don’t understand this feature. Is there an advantage in using worktrees rather than multiple clones? Is it mainly for IDE integration?

permalink
report
reply
1 point

multiple clones

Why would you do this to yourself?

The benefit is that you have everything collected in one place. You can jump between any of your local branches, and there’s no confusion about which state the branches are in.

If you have multiple clones, then there’s the risk that you’ve forgotten to sync main in all your different clones.

Then there’s also the problem that all the generated binaries will be out of sync. You still have 5 copies of each binary.

permalink
report
parent
reply
6 points
*

I use worktrees and I wondered the same question, so far here’s what I like:

git worktrees list can show all the worktrees, you have for this same repo (not crazy value, I know)

git fetch applies to all your worktrees

git stash / apply can work across worktrees, so I can stash in one and apply it to another

You’re limited to a specific branch per worktree and many don’t like that but I typically work from a detached HEAD anyways.

permalink
report
parent
reply
3 points

And cherry-pick commits done on different work trees without syncing them first. Or rebase or mergeworkk done on one work tree with others. Or check commit logs or diff them.

permalink
report
parent
reply
1 point

It’s just clones but with shortcuts, I don’t see the point of m

permalink
report
parent
reply
2 points

You don’t see the point of making use of shortcuts?

permalink
report
parent
reply
1 point

For navigating trough messy systems or unusual places, yes. But you know where you keep your repos. To me, this is bloat.

permalink
report
parent
reply
2 points

did you just shortened “them” to “m”?

permalink
report
parent
reply
3 points

Nah, I just think the ‘m’ should be scrapped from the alphabet

permalink
report
parent
reply
3 points

It’s just them with shortcuts, they didn’t see the point of m

😏

permalink
report
parent
reply
4 points

The different worktrees share the same .git state. The article has an example where the author uses one tree for writing code and one for fuzzing it. If they used multiple clones they’d have to push from the writing directory and pull from the fuzzing directory to get new commits to fuzz but with worktrees this state synchronization between different git directories happens automatically.

permalink
report
parent
reply
4 points

I have started using work trees recently as well, but have a different flow to the author and everyone else. I typically use two work trees, one on main that I do all my work on. That is work and create commits directly on the main branch.

But then to push I have another clean work tree that I use to create and switch branches on then use that to create working sets of changes by cherry-picking from master into different branches to push and create PRS from. And never edit files on this work tree so that I never have to stash anything.

Then just git pull --rebase=interactive origin/master to remove merged commits from master as they get merged upstream. This let’s me build on pending PRs or switch to other tasks at will and just sort them into separate PRs as required.

I like this as when working on a feature I often find a refactoring I need to do, so can isolate that refactoring and create a PR with only that change while continuing to work on the feature on top of the PR.

Or have some temp debugging stuff locally that I want to use across changes that will end up in different PRs without having to copy paste them between branches.

permalink
report
reply
2 points

They wrote they’re using . as placeholder commit messages.

I use f for such [f]ollowup/[f]ixup commits, and a for [a]dditional code/components/changesets. Both keys are trivial to enter. When cleaning it up after, f commits are typically squashed into previous ones, and a commits get a description and/or serve as a base for squashing.

I can see . working well as well, but having a more obvious character (with vertical height/substance) seems preferable.

permalink
report
reply

Git

!git@programming.dev

Create post

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Resources

Rules

  1. Follow programming.dev rules
  2. Be excellent to each other, no hostility towards users for any reason
  3. No spam of tools/companies/advertisements. It’s OK to post your own stuff part of the time, but the primary use of the community should not be self-promotion.

Git Logo by Jason Long is licensed under the Creative Commons Attribution 3.0 Unported License.

Community stats

  • 10

    Monthly active users

  • 221

    Posts

  • 760

    Comments