this post was submitted on 26 Jul 2024
32 points (100.0% liked)

Git

2632 readers
3 users here now

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.

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] sgt_hulka@lemmy.sdf.org 3 points 1 month ago (4 children)

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?

[–] lobut@lemmy.ca 6 points 1 month ago* (last edited 1 month ago) (1 children)

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.

[–] nous@programming.dev 3 points 1 month ago

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.

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.

[–] Boomkop3@reddthat.com 1 points 1 month ago (2 children)

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

[–] Kissaki@programming.dev 2 points 1 month ago (1 children)

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

[–] Boomkop3@reddthat.com 1 points 1 month ago

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

[–] ALERT@sh.itjust.works 2 points 1 month ago (2 children)

did you just shortened "them" to "m"?

[–] Boomkop3@reddthat.com 3 points 1 month ago

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

[–] Kissaki@programming.dev 3 points 1 month ago

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

😏

[–] magic_lobster_party@kbin.run 1 points 1 month ago

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.