0

I want to use git worktree to manage many branches. I have the following problem. I have some scripts I don't want in my branches.

My command is git worktree add src/new_branch. To put new_branches in folder src.

I already tried --no-checkout but when I for example do:

cd src ; cd new_branch ; git checkout -b new_branch2 ; git checkout new_branch

…all files from master are back in the branch new_branch again.

I hope you can help me :)

Obsidian
  • 3,719
  • 8
  • 17
  • 30
Kong Konfus
  • 57
  • 1
  • 5
  • This is Konfusing… – Obsidian Dec 11 '21 at 19:35
  • Files—whether scripts or otherwise—are not *in branches*. What is "in" a branch, in the sense of a [daglet](https://stackoverflow.com/q/25068543/1256452) that is, are *commits*. Files are in *commits*. You check out a specific commit, whether or not you use a branch name, and you get all the files that are in that *commit*, which you can now work on/with. Check out some other commit, and you get some other set of files. The `git worktree add` command simply adds another area where you can check out a different commit, perhaps using a different branch name. – torek Dec 12 '21 at 01:54
  • 1
    It's generally unwise, just from a human perspective, to add a worktree underneath your existing working tree. So `git worktree add src/new_branch` is going to mislead you; use `git worktree add ../new_branch` instead, for instance. – torek Dec 12 '21 at 01:55

1 Answers1

0

I'm not sure I've quite understood the whole issue here, but git worktree is not meant to manage multiple branches in itself, at least not at this stage. git worktree provides you with one or multiple secondary working directories so you can simultaneously check out different revisions of a same repository.

This is useful for instance when you need to compare different versions of a library and need to compile them to do so. However, this won't affect the content of the branch itself.

Also, in order to be ABLE to do so, creating a new working repository implies the creation of another branch, because a given branch cannot be checked out at two different places under a same name : the problem here would be the same that distinguinshes branch and remote/branch: possible discrepancies that need to be resolved afterwards.

Obsidian
  • 3,719
  • 8
  • 17
  • 30