2

I love to use "google drive for desktop", I love to put everything in the cloud since centralize everything makes things organized.

However, is git directory dangerous to be in such syncing drive?

definition of dangerous:

  1. inconsistency of ".git" with "all tracking files". (sync tool may change .git with its tracking file at different times, which may result in disaster when you commit something or push something.
  2. all other possible side effects of letting the sync tool change the .git
Luk Aron
  • 983
  • 6
  • 24
  • 1
    Why aren't you storing your repositories on github? If you are *really* intent on using google drive, you can use [`git-archive`](https://git-scm.com/docs/git-archive) to generate a tarball which you can then store in drive in a "safe" way – joshmeranda Sep 04 '21 at 14:10
  • thanks for the advice, but the question should be answerable even without knowing the intent, it is just asking what it is. – Luk Aron Sep 04 '21 at 14:17
  • 2
    Unless Google Drive or Git indicate that they are compatible, I would assume that it is dangerous and your data will be corrupted. It's the only safe answer. – Jonathon Reinhart Sep 04 '21 at 14:19
  • Note that "the cloud" just means "someone else's computer, over which I have no control". If they damage your data, what will you do? If they take their computer off line, what will you do? Admittedly this "someone else's computer" is convenient, and most of them are really very reliable, but always remember, it's just someone else's computer! – torek Sep 04 '21 at 18:24

1 Answers1

3

I love to put everything in the cloud since centralize everything makes things organized.

Personally, I generally avoid folder-sync services or cloud hosted folders (like OneDrive, Google Drive, DropBox, etc) because they all strive to give users a simple and easy to use experience, which is impossible to do given that the CAP theorem certainly applies to folder-syncing services: so these services' general refusal to let their users have detailed conflict resolution tools - as well as their inability to track changes like splitting-up of files, or even cloned files (looking at you, OneDrive...) just causes headaches.

Is it dangerous to put git directory in drive sync tool

Yes

But it's also moot, because git is already a tool (and entire ecosystem) for keeping repos in sync: just exclude your repos from Google Drive and host your repos with GitHub, BitBucket, or your own self-hosted git server off your NAS or so.

As for why it's dangerous:

  • The main reason is that git's tooling assumes it has exclusive access to your repo's .git directory and that other software won't be peeking at the files while git is working on them.
    • While git does use OS-provided file-locks and other IPC means to ensure exclusive access to its files, third-party folder synchronization software won't be respecting git's own IPC locks.
    • Also consider the wider scope of third-party git tools (GitKraken, Visual Studio's git integration, TortoiseGit, etc) of which we cannot be sure are "safe", as well as users' own shell-scripts for automating git that very likely won't have any kind of locking either.
  • Sync software generally uses features like copy-on-write and shadow-copies to be able to take snapshot copies of locked-files.
    • For example, since Windows 7 (maybe Vista?) Windows' File Explorer uses shadow-copies when you copy-and-paste a file that has an exclusive-lock held by another process.
    • ...which means that while your local .git directory might be in a valid state, the copy of the .git directory held by the sync service may be in a corrupt state (so don't restore it!) because (as far as I know) no third-party folder sync services attempt to make a transactionally-correct snapshot copy of a .git directory.

inconsistency of .git with "all tracking files". (sync tool may change .git with its tracking file at different times, which may result in disaster when you commit something or push something.

Sort-of. As I said, the risk is that when the sync tool is making a copy of your local repo then the sync services' remote-copy of your folder may contain an inconsistent copy of your .git directory where problems won't be apparent until after you subsequently download your folder from Google Drive or DropBox.

all other possible side effects of letting the sync tool change the .git

Too many to mention. Just don't let it happen.


This popular QA features people claiming they got their Git repos working with DropBox, however the highly-upvoted comments warn that their approach won't scale beyond single users (and you should not share a git repo anyway).

Dai
  • 126,861
  • 25
  • 221
  • 322