Today I played around with Github & iCloud

So as recently as only a few minutes ago, I had a minor panic attack. See, normally when I cd around in shell I tab to auto-complete like a fiend. Just now, I actually typed out a directory and was met with an error: it didn't exist. So then I tried to tab auto-complete. It still. didn't. exist. After suffering a minor panic attach I realized: I cloned the repo on my other laptop. No big. Since it was a repo for my own software projects, I should move the cloned repo to be a subdirectory of a shared iCloud directory and then iCloud magic will save me from future self. Right?

Wrong.

→  git co my-branch
fatal: unable to read tree ████████████████████████████████████████

Oh, no problem. I'll just pull the files back down.

Wrong. Again.

→  git pull
error: refs/heads/gh-pages does not point to a valid object!
error: refs/remotes/origin/HEAD does not point to a valid object!
error: refs/remotes/origin/gh-pages does not point to a valid object!
error: refs/heads/gh-pages does not point to a valid object!
error: refs/remotes/origin/HEAD does not point to a valid object!
error: refs/remotes/origin/gh-pages does not point to a valid object!
error: refs/heads/gh-pages does not point to a valid object!
error: refs/remotes/origin/HEAD does not point to a valid object!
error: refs/remotes/origin/gh-pages does not point to a valid object!
error: Could not read ████████████████████████████████████████
error: Could not read ████████████████████████████████████████
error: refs/heads/gh-pages does not point to a valid object!
error: refs/remotes/origin/HEAD does not point to a valid object!
error: refs/remotes/origin/gh-pages does not point to a valid object!
remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
fatal: bad object ████████████████████████████████████████
error: github.com:<ORG>/<REPO>.git did not send all necessary objects

What's going on?

In short? Optimization. See, iCloud storage has a "neat" optimization feature so that "unnecessary" files aren't downloaded locally. The problem with this, as you may have guessed already if you're here, is that git uses a lot of artifacts that get left out of the party and a lack of them causes issues like what I'm seeing above.

What to do?

Option 1: Disable iCloud Optimization

After some research there's no way to exempt a directory from Optimization like you can with Time Machine. Since optimization is either "on" or "off", it's up to you to see if you'd like to turn off optimization overall just for git in particular. As a one-off, if you don't want to turn off optimization, you can try to trigger a file to download by recusively trying to touch and/or open individual files. Caveat: an initial test of this method was not fruitful.

Option 2: Just push the changes

The alternative of course is to just use git as the tool is intended to be used and regularly push your changes. In terms of coolness I do wish I had found a relatively quick-and-easy way to force the iCloud sync situation to work, but in hindsight this would just encourage me to not push my changes as frequently as I so obviously should. And since I have access to my own repos, there's nothing stopping me from using a shell script to clone / pull changes from repos in my org every time I switch between my work and personal computers.

Banner sources: "Like an adult" image shamelessly stolen from the greatly missed Hyperbole & a Half comic. Also iCloud and Github logos.