Search code examples
gitonedrive

Can I use the git in a folder shared between different computers or should I clone the project inside a different folder?


I use Onedrive to sync files between my desktop and laptop. I mostly work on my laptop but I will start to work from home more. Can I just go inside the folder and start to commit changes or should I clone the folder because I am on a different computer?


Solution

  • You should avoid syncing Git repositories between computers with OneDrive or other cloud syncing services. It's much better to clone the repository independently.

    Cloud syncing services tend to sync file by file, which is fine when you're working on a single document. However, Git repositories require multiple files to work correctly, and they write those files in a specific order to maintain the integrity of the repository. If those files get synced in the wrong order, or don't get synced, the repository will be corrupt.

    Moreover, cloud syncing services will sometimes try to restore files that have been deleted from the working tree or copy old versions of the files into the working tree. Those aren't behaviors you want when working with a repository.

    If you absolutely must share a repository with a working tree between computers, you can do so using rsync and ssh, but only when the repository is completely quiescent. You should also be sure to use the --delete-after flag so that you don't delete data until after the repository has been completely synced.