31

In the same flavor as this question, are there any possible complications that can arise when using the two services together?

Community
  • 1
  • 1
Matt
  • 2,576
  • 6
  • 34
  • 52

8 Answers8

33

No, they shouldn’t be used together.

  • Apple says “You shouldn’t store app folders, libraries, or .tmp files in iCloud Drive.” .git is an app folder.
  • There is a list of filenames excluded by iCloud Drive that git doesn’t avoid. So, for example, if you name a tag “tmp”, that tag won’t be synced. There’s also nothing stopping git modifying its internal file structure, or iCloud Drive modifying its exclusion list, such that this sync failure always occurs.
  • iCloud Drive ignores symlinks, git doesn’t. So, git status may return different results on different computers that iCloud Drive is done syncing.

More broadly speaking, git and iCloud Drive are two different lossy implementations of “what are the contents of this directory”, one shouldn’t expect them to be equivalent.

twhb
  • 4,294
  • 2
  • 20
  • 23
  • 7
    I have tentatively trialed using them together for some time and it has worked flawlessly. The issues raised here, in practice, don't appear to be problems. Git, when used properly, tells the user exactly what's going on and mirrors data safely elsewhere so there isn't any chance of data loss and you will be able to identify problems and recover if anything goes wrong (though this has never happened to me). For an experienced git user, I think it's fine to use iCloud drive with caution. Note GitHub defaults to storing all repositories in the Documents folder so it is commonlplace. – Abhi Beckert Sep 01 '20 at 00:26
  • 1
    Most of the time it's working fine. In a few cases, usually involving massive changes (like git bisect) spurious copies of previously deleted files might appear. Never lost anything though. – Alexander Vasenin May 23 '21 at 03:45
21

Be careful especially if you enable the Optimised storage feature, where not all files in iCloud Drive are stored locally and may instead be requested on-demand.

From my tests, it appears git doesn't trigger the OS to request the file, and instead picks up the placeholder file, named something like .original_filename.icloud.

Abhi Beckert
  • 32,787
  • 12
  • 83
  • 110
tobygriffin
  • 5,339
  • 4
  • 36
  • 61
  • 1
    Yep, I believe I'm experiencing this issue as well. On the computer where the repo was created, things work fine. But on other computers there's an error when trying to clone the repo. Do you know of any way to force macOS to get all files first? – Alvin Thompson Sep 20 '16 at 14:06
  • 1
    I've been Gittering about on Sierra since the dev beta and not encountered a single problem, but, the repo is always hosted elsewhere so I've never cloned from it. – tobygriffin Sep 20 '16 at 20:38
  • The way I did it is to actually host the repo on iCloud Drive, then clone it into my `projects` folder on each machine. That way I don't have to spend time/bandwidth synching build artifacts and other ignored files. – Alvin Thompson Sep 21 '16 at 16:05
  • 1
    In any case, I think I figured out the issue I was having (and possibly you were originally having). Originally I used a symbolic link in the path to the repo while cloning. I think if you access a file though symbolic links, macOS sometimes doesn't realize it needs to sync the actual content in iCloud. Once I moved the repo to the `~/Documents` folder (which is now hosted in iCloud), things worked fine. – Alvin Thompson Sep 21 '16 at 16:13
  • I can confirm that Optimised storage does create problems with git. And as far as I know there is no way to exempt a folder from iCloud. – Matt Feb 15 '17 at 21:27
9

TL;DR assuming you're using macOS, you can create a sparse disk image with your repo inside and store this image on iCloud Drive safely


Probably not the answer you're looking for, but I think there is an approach that works quite nice for archive or infrequent access storage of your git repo.

The idea is to create a sparse or sparse bundle disk image using Disk Utility.app. You can put a very large size that will represent the maximum available disk space on the disk image. The actual image file size will only use up as much space as actually used on the inside.

Store this sparse or sparse bundle on iCloud Drive, and all you need to do to access your repo is mount the image whenever needed, then work inside of it. This way, iCloud Drive will only have to sync a single binary file (the image), rather than each separate file of the git repository.

The only drawback is that the sparse or sparse bundle size will not decrease when you delete content inside. You may "reclaim" the free space using hdiutil: hdiutil compact my-special-repo.sparseimage.

I've been doing this for a critical local repository I do not wish to host on a remote server, yet had to make sure I didn't lose it while still being usable and up-to-date in case of hardware loss. Little reminder that important data must always be backed up in multiple places.

Here are the steps for those looking for a synthesised walkthrough:

  1. Using Disk Utility.app, create a new Blank Image
  2. Set a size large enough to hold your repo, it will be the maximum space available
    • Example: an empty 2GB sparse image only uses 8.4MB on the disk
  3. Select sparse disk image or sparse bundle disk image under Image Format
  4. The other settings are at your discretion, I recommend leaving default unless you need to access this image on a Mac that does not support APFS.
  5. The image should be mounted automatically after the creation, if that's not the case mount it manually
  6. Put your git repo inside the mounted image
  7. Eject the image and move it to iCloud Drive
  8. Enjoy your git repo synced across your Macs

Bonus step

  1. The image will not reduce in size even if you delete files inside. If you need to reclaim empty space, use hdiutil compact my-special-repo.sparseimage
Habovh
  • 457
  • 8
  • 20
  • Interesting, thank you. Will this resync the whole disk-file when the contents of anyone file therein are changed? – spac Aug 30 '23 at 01:09
  • @spac any file change inside the disk image will induce a change on the image file itself. It will then sync like any other binary file. It's similar to how it would sync a JPEG being edited and saved again. – Habovh Aug 30 '23 at 09:38
2

I have been using git inside the Desktop which is setup to sync to iCloud for many months. I haven't seen any issues so far.

I guess if you don't do git operations on two Macs in sync you should be safe.

xhg
  • 1,850
  • 2
  • 21
  • 35
  • 3
    just an update: if you have a large git repo, try to move it somewhere else. Recently I experienced performance issues. – xhg Apr 11 '18 at 10:20
2

Yes they can be used "effectively" together, though there are edge cases where you may run into problems. Generally I wouldn't advise doing this if you're unfamiliar with how both iCloud and Git behave, and I'd avoid anything with symlinks or large projects with many contributors.

Be especially careful if you use the "optimise storage" feature - it might force you to fix things manually from time to time - but in my experience this is mostly only an issue if you haven't worked on a project for months, and in that case I appreciate saving disk space by not keeping a local copy of every project I've ever worked on.

I find iCloud Drive is a very nice way to have access to all of my repositories across all of my devices (office desktop, home desktop, laptop, tablet, phone).

Abhi Beckert
  • 32,787
  • 12
  • 83
  • 110
1

I just added a git repo to my iCloud drive on Windows. It looks fine there, but the iCloud drive is polluted with folders named 00 thru ff both on the website and on my mac, as well as a mysterious assortment of items from the repo flattened into the root of the drive.

So I certainly wouldn't recommend it.

0

You should use a solution similar to git-remote-dropbox that accounts for the characteristics of a synced file system to avoid corruption. It is possible that git-remote-dropbox would work with iCloud Drive out of the box.

Markus Miller
  • 3,695
  • 2
  • 29
  • 33
0

I tried iCloud sync git repository to three Mac machines, among two machines encounter login black screen and freeze symptom always. And Mac running very slow.

Open activity monitor and discover where one 'bird' process just sits there at almost 100% CPU usage all the time without actually accomplishing anything.

The process is linked with the iCloud sync (refer here). Solved this issue once iCloud logout.

Base on other git repo sync discuss, Google Cloud Build may consider.

Joshpy
  • 560
  • 8
  • 21