0

I use OneDrive to sync my personal projects between all the machines I work with (home desktop, notebook and the computer at work). In my home PC, I have a git repository in the following path:

I:\OneDrive\Documents\Projects\MyProject

In my work computer, the OneDrive base location is mapped to a different path, so that folder syncs to:

C:\Users\MyUser\OneDrive\Documents\Projects\MyProject

I use VSCode with git integration and everything works fine in my home computer, but when I open the repo with VSCode in my work computer, it doesn't recognize the repository. If I open the config file inside the .git directory, I can see that worktree is pointing to the absolute path of my home machine:

worktree = I:/OneDrive/Documents/Projects/MyProject

I think git is trying to find this path in my work computer, which doesn't exists (as the OneDrive is mapped to a different location), and so it don't recognize the repository in VSCode.

Is there a way to fix this? Can I make git use relative paths when dealing with the repo location? I tried changing the worktree to ../ but that doesn't seem to work.

Thanks!

Fergo
  • 57
  • 7

1 Answers1

2

Normally you don't need to set the worktree config in git repositories. You should be able to delete this particular config parameter. In this case the working directory is where your .git folder is located at (which in your case changes from work computer to home computer). This .git folder should be in the root of your project e.g.:

I:\OneDrive\Documents\Projects\MyProject\.git

Any Tool with git integration should pick up the correct working directory for this project.

Nevertheless I highly recommend to use an external git repository, e.g. https://github.com. OneDrive is not an ideal place to store your project, it might be ok if only you work in this project, but fails if someone joins the project. Syncing git objects is probably also a pain for OneDrive, which will scale horribly on larger projects and might corrupt your git repository on failed syncronizations.

Also the beauty of git is that you don't need a centralised git repository (which is what you are basically doing right now with OneDrive), but in fact git is a distributed version control system. Some further readings here: https://www.git-scm.com/about/distributed

If you insist on going with OneDrive, you should use the OneDrive location as an upstream location only. Meaning you pull from OneDrive and push to it. How do I use git without having a proper git server? demonstrates how to do this.

Dennis K
  • 113
  • 7
  • Thanks! Removing that parameter indeed fixed the issue. Regarding the OneDrive thing itself: I don't usually code in team, so I mainly use git to track changes to my own code. Nevertheless, you are right about corrupting the repository due to failed 1D sync, as it already happened to me once. I'll take a look around only using the 1D foder as the upstream location and pulling/pushing from it. – Fergo Jan 14 '20 at 03:49