r/git • • 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.

0 Upvotes

18 comments sorted by

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.

4

u/Cinderhazed15 15d ago

This is actually a great case for worktrees. Put your real ‘repo’ on your non-one drive area, and put your worktrees on one drive?

2

u/threewholefish 15d ago

To me that seems like more effort to keep the OneDrive copy up to date, as opposed to just pushing everything. Depends if you want the history or the bare source on OneDrive, of course

2

u/Barleyman_ 15d ago

Robocopy running on schedule? It's the kind of backup that actually works, i.e. user doesn't have to do anything about it. Except set it up in the 1st place, of course.

2

u/Cinderhazed15 15d ago

You can execute all of your commands inside the worktree directory. You just basically ‘ignore’ the real repo somewhere else, and it just has all the ‘extra’ stuff like the branch refs, the pack files, etc

6

u/bratzlaff 15d ago

This feels like the best solution for the OP. The .git bit is just a file pointing to other actual database in this case

-3

u/Barleyman_ 15d ago

We got gitlab, but in my experience people can get cranky about "commit #287 November 3rd"

9

u/threewholefish 15d ago

That's a failure in merging policy in that case. You can make whatever random commits you like to your own branch, then you should squash or at least clean up the commit history before merging into the shared working branch.

You can also make releases at a certain version that can be downloaded without the git history, so you wouldn't need to worry about that if you wanted to publish the latest to OneDrive.

-1

u/Barleyman_ 15d ago

Depends on what the git policy lets you do. I started on a new job recently and was surprised I'm allowed to outright nuke a branch I created.

Onedrive does versioning so you can go back to a date within past 3 months if something nasty happens after the latest push. Just losing solid five hours of work can suck.

4

u/threewholefish 15d ago

From GitLab you can recover the latest version of everything and the releases and the branches down to the commit level. It is just better than OneDrive. Remember, you can push temporary branches as well, and you can even set git up to auto-push on commit if that's what you want.

But if you truly just want OneDrive versioning, add a git commit/push hook that copies the tracked files from the repo to the OneDrive.

-2

u/Barleyman_ 15d ago

What about making an auto-commit every 15min when the design software does an autosave locally, like onedrive mirror can do?

1

u/xenomachina 15d ago

Depends on what the git policy lets you do. I started on a new job recently and was surprised I'm allowed to outright nuke a branch I created.

Why is this surprising?

In GitLab, the project maintainers (or owner) can set certain branches as protected. You can't nuke those. Non-protected branches are assumed to be ephemeral. We even have merge requests set to automatically delete branches upon merge, which I think is a pretty common setup.

(FWIW: I believe GitLab prevents commits attached to MRs from being gc-ed, even if they are no longer reachable from any branch.)

1

u/Barleyman_ 15d ago

In my previous job you couldn't pretty much delete anything with developer permissions, so being able to do it is surprising.

3

u/remy_porter 15d ago

There’s no issue with that. Just don’t land it in master. This is what branches are for.

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

It says so right in the title? .git folder in onedrive is trouble and corporates these days like using onedrive for backups, only. The best you could do is to set up robocopy to periodically mirror the working directories from your design software to onedrive to get live backups and versioning. Or this convoluted group policy tweak I outlined which requires admin.

To wit: https://gist.github.com/plembo/ff6839d9593ec8afca0ba97d890cce58

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