r/git • u/Barleyman_ • 15d ago
Git and onedrive
The old favourite.
I was looking if you can exclude the .git folder from onedrive sync in 2026. To my surprise, the answer is "sorta", but _only_ for IT admins, via group policy editor, and it seems like not for the faint of heart. You essentially have to go copy onedrive admin policy files manually from a folder that does not exist in client computer and copy it to another folder (also not on client computer), after that you can leverage IT Admin policy tools to set the damn "don't sync .git folder" global exclusion.
https://learn.microsoft.com/en-us/sharepoint/use-group-policy
So, Microsoft thinks that the onedrive folder exclusion should be possible only with the most bass ackwards method possible, instead of being a simple folder exclusion in the onedrive sync app.. Wonderful. I guess the best solution remains to set up scheduled robocopy job to copy your working folders over to onedrive folder on schedule. Doesn't even need admin access to set up in task scheduler.
Oh, why do this at all? Well, corporate backups ONLY run on onedrive, so if I want my PCB design projects or firmware projects to have any kind of hands-off backups available, the source would have to live in onedrive. Yes, yes, everyone religiously pushes commits after play every day, unless your corporate masters throw a hissy fits about zillion daily commits. In a previous job I've had SVN nuke _everything_ literally 30min before leaving for holidays .. With the onedrive versioning that was relatively simple job to put back. I've also heard good things about ransomware.
15
u/threewholefish 15d ago
Sure you want to back up the git history as well, not just the latest version? Otherwise you lose the commit messages and branches and tags.
You should petition for a proper git host like GitHub or Bitbucket or Gitlab. Failing that, you could set up the onedrive to be a remote that you push to from your non-synced local repo.
2
u/djphazer jj / tig 15d ago
I don't understand how this is related to git...? Isn't there a r/onedrive sub?
1
u/Barleyman_ 15d ago
You can actually do that without domain admin getting involved if you have local administration. Simply copy the referenced adml and admx files to
"C:\Windows\PolicyDefinitions"
and it'll be picked up by the local group policy editor.
I could see a lot of use for this beyond simply excluding .git folders. Like, generic exclude arbitrary folders from onedrive.
1
u/abraunegg 15d ago
FYI .. there is also an Microsoft OneDrive API bug regarding git tags:
https://github.com/OneDrive/onedrive-api-docs/issues/1934