Obsidian-git users : How to put the ".git" folder outside of my vault (to avoid sync issues with iCloud)?

Hi,

My desktop vault (Windows 11) is synced to my Android phone with Syncthing, and to my iPad with iCloud.

I have set isDesktopOnly to true in obsidian-git settings. The .git folder is excluded from Syncthing.

Now, for security, I would like to put the .git folder outside of my vault, somewhere on my computer (like C:/user/documents), so that iCloud does not mess with it (so far, a year without any issues, but I’d like to avoid possible issues in the future).

Is such thing possible ?

I’m confused as to which setting I should use (Custom base path ? Custom Git directory path ? Can we use a full path like C:/user/documents/ ?)

Thank you very much.

Git expects that hidden .git folder to be in the top directory of whatever you are putting under source control i.e. your vault. It’s not easy, as far as I am aware, to move it anywhere else that obsidian git will find it. For a normal git repository it can be put anywhere, as long as the GIT_DIR environment variable is set. But that’s not an obsidian git thing. I’ve had .git directories in vaults before, but i don’t use obsidian git. I’ve then synced those with dropbox without issues. However that .git directory can get pretty large when lots of changes are made since all the versions of the files are hidden away in there. Since dropbox already does a form of version management, i decided to just delete the .git directory. I found obsidian git to be more trouble than it was worth. But that was two years ago, so it may have improved.

1 Like

Thanks.

I understand, but then what are these “Custom Git directory path (Instead of ‘.git’)”, “Custom base path (Git repository path)” settings in obsidian-git ?

Also, I heard about moving the .git folder elswhere, and putting a .git file instead with the path of the moved .git folder inside.

Don’t know. But Git requires a whole directory called “.git” and will place quite a few things in there to manage a repository. Not heard of the file with the path to the real thing, but it might be worth trying. I would experiment. If it works, when you type “git status” on the command line anywhere in the vault, it should show you a valid status if it can find the “.git” directory.

OK. To try and help here i’ve created a test vault and installed the obsidian-git plugin. When I change the welcome note to add a new line and then run “git status” i get this:

carolinemathieson@MacBookPro Test % git status
On branch main

No commits yet

Untracked files:
(use “git add …” to include in what will be committed)
.DS_Store
.obsidian/
Welcome.md

nothing added to commit but untracked files present (use “git add” to track)

Which is what i would expect to see.

Then i closed down obsidian.

When i moved the “.git” directory onto my desktop and created a file called".git" with the path to that directory on the desktop, Obsidian then complained about there not being a valid repository.

This is without changing any of the settings in the plugin. I then changed the repository path in the setings and reloaded obsidian. But it didn’t like either the new path or file. Tried removing the file but leaving the directory in place and no difference.

My first thought is that this may not be possible. It may be the seting isnt quite right but someone who knows the git plugin would be able to give better advice.

I didn’t feel like trying any further experiments.

I’m sorry : it’s not the “PATH” only, it’s “gitdir: PATH” !

When you initialise a git repository, it will try to manage everything in the main directory. You can tell it not to manage the hidden .obsidian directory using a .gitignore file for instance.

I use Git all the time but from the command line or from within an IDE. I’ve not tried using the plugin for a long time, so not sure what you mean by “gitdir: PATH”.

I meant, this is what you have to put in the .git file ! Not just PATH of the .git folder you moved, but gitdir: PATH : it should work !

I see. Have you tried it and did it work?

Just tried that and Obsidian still wasn’t happy with it.

Yeah, trying right now to make it work, I get an invalid gitfile format error. Will update.

I get the same and also the vault not initialised error.

Ok, I think I made it work.

First, I initialized the vault with the appropriate obsidian-git command.

Then I moved the .git folder outside and specified its path in a .git file with gitdir: RELATIVE_PATH inside (should work with an absolute path as well).

Make sure to write gitdir and not gitir, which is a common mistake.

where did you hear about the “.git” file trick because a quick
google search isnt showing anything.

Someone on Reddit where I asked the same answered with this solution ! I’ll ask him how he discovered this.

Also, I just found that it is briefly mentioned in the git documentation here (in “Note” paragraph) : Git - gitrepository-layout Documentation.
It’s not very explicit that we can move .git folder elsewhere with this .git file trick (for the use case discussed here I mean), but it seems to work…

hmm,

Note: Also you can have a plain text file .git at the root of your working tree, containing gitdir: <path> to point at the real directory that has the repository. This mechanism is called a gitfile and is usually managed via the git submodule and git worktree commands. It is often used for a working tree of a submodule checkout, to allow you in the containing superproject to git checkout a branch that does not have the submodule. The checkout has to remove the entire submodule working tree, without losing the submodule repository.

Maybe i have a setting in the plugin wrong? i only changed the path one. However deleting that and reloading stops obsidian from complaining about the gitfile but still complains about not finding a repositiry which is progress.

I made that experiment in a new vault with default obsidian-git settings.

First I used the “Git : Initialize a new repo” command. Then moved the .git folder elsewhere (just above in the tree hierarchy) and put a .git file in my vault with gitdir : ../.gitREPO (yes, I also renamed the .git folder as .gitREPO to check if we could change name).

Sorry I could not help but i’ve learned something i didn’t know which might be useful another day.

So you made it work too ? Nice, isn’t it ? Now I won’t be afraid that iCloud would mess with my .git folder !

Thanks for your presence which helped me set up & debugging this solution !

I didnt get it work since obsidian didn’t like it. But as i have no intention of using the plugin, it does not matter too much. I only used it today to try and help.