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).