Subject: Re: What is the reason behind not hiding git worktrees from git?

From: Junio C Hamano <[email-masked]>
Date: Sat, 27 Sep 2025 09:52:56 -0700

"Jakub T. Jankiewicz" <[email-masked]> writes:

> Why git work trees are are not automatically ignored by git?

Because there is no reason to ignore them, and ignoring them would
be annoyingly inconvenient.  Worktrees are not special and treated
the same way as an ordinary Git working tree with embedded .git
directory.

That is, if you "git clone" somebody else's project into your
current directory, when you are in the working tree of you git
repository, that working tree of the cloned repository would appear
as an untracked content from the point of view of the containing
repository of yours.  It is up to you to add it as a subproject, or
leave it as an untracked directory.

If you do not want to see a new worktree as an untracked directory
in another repository, do not do

    $ git worktree add base

in the first place.  You are creating the new worktree _inside_ an
existing repository's working tree, and it is no surprise that the
new directory appears as an untracked directory.

In other words, if it hurts, don't do it.

Instead, you can create your additional worktree outside the working
tree you are using.  For example, I keep a handful of worktrees just
next to my primary working tree, by doing something like

    $ git worktree add --detach ../git.maint maint
    $ git worktree add --detach ../git.next next
    $ git worktree add --detach ../git.seen seen

when I am in my primary working tree.  Then I can leave some work in
progress in my primary working tree and then context switch out to

    $ cd ../git.next && git reset --hard next
    $ do stuff on next

any one of these additional worktrees.

Hope this helps.