Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does "git config core.worktree" mean?

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

like image 995
flod Avatar asked Mar 06 '23 06:03

flod


1 Answers

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.

like image 79
CapinWinky Avatar answered Mar 20 '23 22:03

CapinWinky