Search code examples
gitgit-worktree

Using hardlink to .git instead of git worktree


There is a known bug in Eclipse which prevents it from working with git worktree.

The only practical work-around I can think of is creating .git hardlink from secondary (branch) working copy to the primary one containing the real .git folder.

What might be the negative consequences of such a work-around (on Windows platform)?


Solution

  • You probably don't want to do this. A worktree includes its own version of HEAD, the HEAD reflog, and the index. This is required because you have two separate branches checked out and you can stage files in each worktree independent of the other one.

    If you hardlinked .git into another directory, you'll actually have the same HEAD, so you'll be on the same branch. Also, you'll have the same index, so as soon as you run git status in one directory, running it in the other directory will cause every file to be re-read. That's in addition to the fact that if you run git add in one directory, it will be reflected in the other as well.

    As a result, this is likely to lead to a bunch of unhappiness and possibly some repository corruption. If you want to continue to use Eclipse, use separate clones, or you can use a different editor if you want to use worktrees.