42

I am trying to create a git repository located within a OneDrive synced folder, but I am running into an issue.

I use OneDrive to sync folders between my multiple devices via "the cloud". On my development machine (Win 7 64) the OneDrive folder is located under C:\Users\myusername\OneDrive.

I created a \git subfolder in that directory and created a git repository for my code (foo.git) within that folder.

On the same machine, I can clone that repository to another folder, that is not synced with OneDrive, and push and pull changes.

However on my other machine (Win 8.1 64), which syncs with OneDrive as well, when I try to clone the repository (looks like everything is in there under C:\Users\myusername\OneDrive\git\foo.git), I get a "this is not a valid git repository" error.

The \git folder contents "should" be identical between the two machines, as they get synced. Only thing I can think of is that there may be some hidden folders/files in my git repository that are not getting synced. OneDrive is supposed to be to syncing everything, including hidden files and folders (as far as I know).

Are there hidden folders or files in a remote git repository?

I am not sure why this isn't working, I have read of others that use OneDrive to store a git remote repository without a problem. Maybe its some issue with one machine being Win 7 and the other being Win 8.1?

As I have exhausted my googlingfu trying to find a resolution, does anyone have any advice or insight as to what I might be doing wrong?

Ryan
  • 797
  • 1
  • 6
  • 14
  • Try this [blog](http://foyzulkarim.blogspot.in/2012/12/dropbox-as-svn-repository.html) which works fine with SVN. Should be work same for GIT too. – Babulu Sep 12 '14 at 23:18
  • 3
    I have a similar issue. Onedrive displays a merge error, and keeps creating duplicates of FETCH_HEAD file in the .git directory and appends my PC's name to the name. It seems like an endless loop. Is there a solution to this, or I have to write a bath script to clear those duplicates? – Vin Shahrdar May 05 '17 at 00:49
  • 1
    @VinShahrdar I have the same issue. I think the reason is that when you run `git fetch` Git updates the file many times very quickly (once for every new/updated branch?), so that OneDrive starts to sync it but it gets overwritten before it's been uploaded to the cloud, and OneDrive sees it as a conflict. Which is wrong, but that's the way it is. Luckily it looks like it's harmless: the conflict copies are simply outdated, and you can just ignore them, or delete them. – Fabio says Reinstate Monica Dec 21 '21 at 15:21
  • 1
    Am I the only one to suggest _not_ to have a git repository in a OneDrive backed folder? The two (OneDrive sync and git) might not play well together. – theking2 Aug 10 '22 at 17:56

8 Answers8

56

The OneDrive sync client now supports syncing folders that contain the period character within them '.' this should enable you to start syncing those git repositories automatically so long as they are within your OneDrive folder.

Get the latest version of the OneDrive Client and you are all set.

Peter Nied
  • 1,820
  • 1
  • 13
  • 22
  • Do you know if this also works with the consumer version of OneDrive in Windows 10? I haven't updated yet, and your link installed the OneDrive for Business client on my 8.1 machine. – Leon Overweel Aug 09 '15 at 17:18
  • 1
    also works in OneDrive for Business now, but Windows only, Mac (15.3.0 beta) still can't sync, "The folder path contains invalid characters or unsupported extension". – leoce Aug 15 '15 at 03:41
25

OneDrive does not (yet!) support syncing files that start with periods, like the .git folder where the git metadata is saved to.

Because of this you are not seeing those items sync over OneDrive.

(This is only the case with old version of the OneDrive Client, I've created a new answer that reflects the current versions capabilities 8/2015)

Peter Nied
  • 1,820
  • 1
  • 13
  • 22
  • In a local git repository i definitely see a .git folder, but where is that folder you speak of in a remote git repository (not seeing it). – Ryan Sep 11 '14 at 18:22
  • If you look on http://OneDrive.live.com you will not see the .git folder which contains all of the branch/remote/commit history specifics – Peter Nied Sep 11 '14 at 22:49
  • 1
    Whenever I launch Git Shell, OneDrive refuses to sync (even after a day). If I close Git Shell and close OneDrive, and then reload OneDrive, it syncs. Any ideas why? Is this related? – Xonatron Aug 09 '16 at 18:34
8

As of 6/27/2017, Version 2016 (Build 17.3.6917.0607)

OneDrive for business will support synching dotfiles (and dotdirectories) However, OneDrive is a VERY bad solution unless you add commit hooks to exclude files: https://support.microsoft.com/en-us/help/3125202/restrictions-and-limitations-when-you-sync-files-and-folders

Also, I dont know about how things would behave under race conditions. If there is more than one committer (inc automated stuff), it might not be safe.

Alan Berezin
  • 533
  • 4
  • 13
1

Manual creating folder with name ".git" works, and ".git" appears on the onedrive server.

dvda
  • 11
  • 1
1

Manually syncing from office.com and patiently merging any conflicts worked for me so far. Next test will be to see how it performs day-day. I know that oneDrive is not an ideal solution, but for privacy sometimes it is an easy way to get GitHub-like functionality for passing files back and forth between workspaces.

1

I'm not answering the question as I believe there is not a straight forward answer. But the use case is compelling. Let's assume I like to keep all the projects I'm working on in a projects folder within the OneDrive synced folder with all the Office magic as added value. Lets assume it is a web project. I'd have

OneDrive/Projects/
    Project A/
    Project B/
      Documentation/
        UserManuals/
      Backups/
        2020-09-16/
      SQL-queries/
      htdocs
         .git
         .gitignore
         assets/css
         index.php
      Research/

Of the folders in Projekt B I'd like to sync all but htdocs (and perhaps the Backup) folder as it already is under some sort of version control (git) with a Git server (BitBucket). For me this is a very common thing and I have yet to come up with a satisfying solution. Of course I could move out the htdocs folder (and Backup) to somewhere outside the OneDrive tree, but that would make the layout brittle and finalizing and archiving the project would not be straight forward. One solution I could think of would be to move Projects outside OneDrive, add the stuff to be synced in a separate folder and add this folder as a symlink inside the OneDrive folder struct.

theking2
  • 2,174
  • 1
  • 27
  • 36
1

I thik Per Mikkelsen has a solution here: https://www.permikkelsen.dk/how-to-host-your-git-repository-on-onedrive.html

The method is to create a remote repo on Onedrive, which will be cloned on the local(s) machine(s)

  1. On Onedrive (that is, on the local mirror of your Onedrive on your machine), create the directory of the future repo. let us assume its windows path is C:\Users\me\OneDrive\Documents\myrepo
  2. Step into the directory, use git bash here and issue command: $ git init --bare. You can check that the directory has now all the files of a git repo
  3. On the local file system, go to the directory that will contain the future local repo, (for example C:/R). use git bash here and issue command: $ git clone file:///C:/Users/me/OneDrive/Documents/myrepo. Note the file:/// prefix and the forward slashes

You have now a local repo with a remote on your Onedrive, which is going to be synced automatically to all your machines. It works for me. I hope it helps.

B.Fischer
  • 21
  • 3
-4

I had the same using DropBox and also OneDrive.

It takes some time before folders are completely synced and the other clients are completely aware of the changes. If something is missing git complains as it is expected to do.

Manually forcing a sync on both sides solves it.

I suspect that the way it's implemented on (or used by) Windows causes it. Dropbox on Ubuntu didn't show the issues. (Unless I was to much in a hurry and expected a full sync on my other box 3 secs later ;-))

I gave up on the DB & OD solution. In the end I decided to take an account on github. Much more convenient.

Installing something like GitLab or Gitblit (using Tomcat on Win) on a box will help too for private repos.

lboshuizen
  • 2,746
  • 17
  • 20
  • Its been a day of both machines being on the same network, so they should have been synced by now, but the clone still fails. I have synched my OneNote workbooks several times since via OneDrive, and everything seems to be in order. – Ryan Sep 09 '14 at 01:01
  • Seems but sadly it ain't. (At least not on Win) – lboshuizen Sep 09 '14 at 01:06
  • I can't create a private repository on GitHub (I don't want my code to be shared just yet), without a paid account. That's why I was trying the OneDrive approach, since I already use OneDrive and its supposedly can work. – Ryan Sep 09 '14 at 01:08
  • How do you force a OneDrive folder sync? I don't see that option. – Ryan Sep 09 '14 at 01:09
  • It's quite easy to setup something like GitLab on a box. It ain't completely github but works for sure – lboshuizen Sep 09 '14 at 01:10
  • @Ryan you could just use [bitbucket](http://bitbucket.com). as many private repos as you want. – yamm May 21 '15 at 12:03