6

I'd like to use local file exclusion on a worktree. I tried adding the file name to .git/worktrees/$worktreename/info/exclude but it doesn't take. The analogous file .git/info/exclude works, but applies to all worktrees, not just the main one.

Cactus
  • 27,075
  • 9
  • 69
  • 149

1 Answers1

5

but it doesn't take

I do not see an info/exclude in .git/worktrees official layout documentation.

A workaround would to have a branch-specific .gitignore content.
That means adding your untracked file to the worktree .gitignore remains the best option.
And you can ignore modification on that (tracked) .gitignore file with the update-index command seen here.

git update-index --assume-unchanged -- .gitignore

That allows you for the local exclusion you are after.

Cactus
  • 27,075
  • 9
  • 69
  • 149
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I am not using Visual Studio. I was using Git 2.15 when I asked the question, but upgrading now to 2.16 didn't change the behaviour. – Cactus Feb 14 '18 at 07:16
  • 1
    @Cactus Then my comment about git/wortrees layout stands: there does not seem to be any .git/worktrees/info/exclude file managed by Git at the moment. – VonC Feb 14 '18 at 07:19
  • @Cactus Note that if by "local ignore" you mean ignore modification for an already tracked file, that would be done with a git update-index command: https://stackoverflow.com/a/3354629/6309. For an untracked file, adding it to the .gitignore remains the common solution. – VonC Feb 14 '18 at 07:30
  • no, that's not what I mean -- the behaviour I am after is exactly as if I had multiple independent repos instead of worktrees, each with its own `.git/info/exclude` file. – Cactus Feb 14 '18 at 07:30
  • @Cactus So we are talking about untracked file, right? – VonC Feb 14 '18 at 07:31
  • yes, I am talking about untracked files that I don't want to show up in `git status` etc. – Cactus Feb 14 '18 at 07:32
  • Another option would be to set per worktree, the config `core.excludesFile` in order to reference a different file on each worktree... but I do't think you can have more than one local config (https://git-scm.com/docs/gitrepository-layout#gitrepository-layout-config) – VonC Feb 14 '18 at 07:36
  • 1
    So, adding your untracked file to the worktree .gitignore remains the best option. And you can ignore modification on that (tracked .gitignore file) with the update-index command I mentioned before in https://stackoverflow.com/a/3354629/6309 – VonC Feb 14 '18 at 07:37
  • can you edit your answer to contain the final conclusion, so I can accept it? – Cactus Feb 15 '18 at 01:33
  • I solved this just by an adding entry to my global gitignore file. Yes, not quite as clean, but, it works great. – Devin Rhode May 26 '21 at 04:28