gitgit-worktree

git status in git worktrees show HEAD, ORIG_HEAD, COMMIT_EDITMSG, logs


When working with git worktrees and I do git status in one of the checked out branches I see stuff like HEAD, FETCH_HEAD, index.lock, ORIG_HEAD, commondir, gitdir, index, COMMIT_EDITMSG, logs/

REPREX

$ git clone --bare https://github.com/octocat/Spoon-Knife
$ cd Spoon-Knife.git
$ git worktree add -B main worktrees/main main
$ cd worktrees/main
$ git status
On branch main
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        HEAD
        ORIG_HEAD
        commondir
        gitdir
        index
        logs/

nothing added to commit but untracked files present (use "git add" to track)

Shouldn't this files be hidden from git status? Am I doing something wrong?

Workaround: I added them to myrepo.git\info\exclude but it feels I shouldn't have to do that.

Note: git version 2.43.0.windows.1


Solution

  • git worktree stores metainformation about worktrees in a subdirectory named worktrees. You're very much advised to not overuse the subdirectory to store your real worktrees. Use a different name (also not clashed with other Git internals like modules or objects). Anything like this:

    $ git worktree add _worktrees/main main
    $ git worktree add worktrees_/main main
    $ git worktree add ../worktrees/main main
    

    The last one is the best IMO. Do not put anything into Git-managed subdirectories.