what does "git config core.worktree" mean?
Asked Answered
C

3

10

I have seen this line in a script I am using :

git config core.worktree ..

I'm not sure what does git worktree do, but I definitively do not understand why to set it to ..

Any clue ? Thanks

Consistent answered 10/10, 2018 at 14:22 Comment(3)
Possible duplicate of What would I use git-worktree for?Unwrap
stackoverflow.com/search?q=%5Bgit%5D+%22core.worktree%22Whirlpool
git-scm.com/docs/git-config#git-config-coreworktreeWhirlpool
R
7

Git has two strategies to separate the place your repository folder is (GIT_DIR) and the place the files being tracked by that repository are (GIT_WORK_TREE, aka the main work/working tree).

core.worktree changes the location of the main worktree. In your case, from the default equivalent of . to .. which is the parent directory of the one containing the repository folder. Using relative paths in core.worktree that are outside of GIT_DIR is the kind of thing you do alone in your room and not in public.

Why would they do this? To track the same files in multiple repositories; the original dev probably had several repositories in sub folders of that parent folder all using .. for their core.worktree config. As the previous answer mentioned, it could be a way to share libraries, but there are better strategies to do this.

Since I brought it up, you can take any git repository and replace the .git repository folder with a .git file that contains gitdir: <some path> to point to a new location that will act as the repository folder. It's important to note that <some path> contains the repository folder name and thus this is a way to change the repository folder name so it isn't .git. When doing this, you execute your git commands in the location of the .git file as it is now masquerading as the repository folder.

Important Note:

The vast majority of git GUIs do not correctly support core.worktree. Any repository using this configuration option should be handled only via terminal commands.

Runthrough answered 12/5, 2021 at 10:13 Comment(0)
F
4

.. means the parent directory.

I'm not sure if you are asking about the .. syntax, or why the script is using the parent directory.

And for git config core.worktree, see https://git-scm.com/docs/git-worktree

You may want to post the script so people could understand why the parent directory is used.

Ftc answered 28/10, 2019 at 17:52 Comment(0)
H
2

It could be a form of library sharing strategy.

The content of the repo you are configuring is most likely shared by multiple other repos via submodules - but whoever wrote that script want to reference all of them to the same working copy locally (as opposed to every repo having its own local copy).

There are pros and cons...
See: Git: Possible to use same submodule working copy by multiple projects?

House answered 12/11, 2019 at 16:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.