How to omit directories from Optimized Storage?

Solution 1:

Currently there is no way to exclude subdirectories/files present in Desktop & Documents Folders, if you choose to store them in iCloud and enable Optimize Mac Storage.

A possible workaround for your situation could be to move the git repositories to any directory which is not a subdirectory of ~/Desktop or ~/Documents directory.

A commonly used subdirectory for storing repositories is ~/Developer.