Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Per-worktree local exclusion

Tags:

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.

like image 462
Cactus Avatar asked Feb 14 '18 04:02

Cactus


People also ask

What is a Worktree?

A Git worktree is a linked copy of your Git repository, allowing you to have multiple branches checked out at a time. A worktree has a separate path from your main working copy, but it can be in a different state and on a different branch.

How do I remove Worktree?

To remove a locked worktree, specify --force twice. With add , create a new branch named <new-branch> starting at <commit-ish> , and check out <new-branch> into the new worktree. If <commit-ish> is omitted, it defaults to HEAD . By default, -b refuses to create a new branch if it already exists.

What does Git Worktree prune do?

prune Prune working tree information in $GIT_DIR/worktrees. remove Remove a working tree. Only clean working trees (no untracked files and no modification in tracked files) can be removed. Unclean working trees or ones with submodules can be removed with --force.

How do I change my Worktree?

Create as many worktrees for a detached HEAD as you want to. You can run git worktree add /path/foo1 refs/heads/master , git worktree add /path/foo2 refs/heads/master , ..., git worktree add /path/fooN refs/heads/master . Reset develop to master . In "project_develop" worktree, run git reset master --hard .


1 Answers

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.

like image 139
VonC Avatar answered Sep 23 '22 13:09

VonC