Mauricio Lomelin

How I Organize Source Code on My Computer

The way I organize source code on my computer has changed over time. It has been influenced by guidelines I have followed at large corporations, standards I’ve helped establish within growing teams, and simple pragmatic rules I follow on personal projects.

At a very high level, this setup is a part of how I organize my data globally. I designed it around three requirements:

  1. Independence. Maintain a structure that is independent of folders managed by the OS (such as Documents/ or Library/) to ensure it works on macOS, Windows, or Linux.

  2. Portability. Create a walled garden workspace that is easy to set up or tear down, and work identically across machines.

  3. Efficiency. Establish path predictability so that scripts and workflows remain consistent across environments.

Directory Structure

This is my current setup on macOS, in path form:

# Workspace root folder.
~/_dev/

# Active repositories.
~/_dev/repos/{remote}/{account}/{repo}/

# Repository snapshots.
~/_dev/snapshots/{account}--{repo}--{description}.(zip,tar.gz)

# Experiments.
~/_dev/scratch/

And in tree form:

~/_dev/                         # Workspace root folder.
├── repos/                      # Active repositories.
│   └── {remote}/
│       └── {account}/
│           └── {repo}/
│               └── ...
├── snapshots/                  # Repository snapshots.
│   └── {account}--{repo}--{description}.(zip,tar.gz)
└── scratch/                    # Experiments.
    └── ...

Folder Contents

Everything is under ~/_dev/

Active repos are in ~/_dev/repos/

Repo Snapshots are in ~/_dev/snapshots/

Experiments are in ~/_dev/scratch/

Failed Iterations and Dead Ends

I thought it worthwhile to share some dead ends I encountered on the road to my current setup. I hope documenting my mistakes helps you avoid them.

Do Not Cloud-Sync Your Workspace

I once set up my workspace root folder in an iCloud drive on one of my laptops.

Everything worked fine. I had a cloud-synced backup as well as my GitHub remote, and that felt like a good safety net.

Then I went ahead and set up my workspace on a second laptop. I missed the obvious: iCloud synced updates from the second laptop with an active repo on the first. I did not notice until I went back to work on my primary laptop. I followed my usual push/pull/sync workflow. And then Warnings. Errors. Sync Conflicts. I was mystified until it dawned on me… Ugh… I ended up rebuilding the repo and lost all commit history in the process.

Lesson learned: Never configure a directory with two or more competing sync engines.

GitHub Gists Are Not Regular Git Repos

I once tried setting up a top-level folder for gists, ~/_dev/gists/.

I was motivated by GitHub’s “Creating gists” documentation, which states that gists are Git repositories.

I set out to create a library of gist repos similar to regular repos. Gists have no repo name, but they can be uniquely identified by their {gist_id} (e.g., dc591f733ac66699ff81f14acc6b290d). I’d add the {gist_name} for readability, and because the naming convention differed from regular repositories, a separate ~/_dev/gists/ folder felt like a natural choice:

~/_dev/gists/{remote}/{account}/{gist_id}--{gist_name}/

Gists, however, turn out to be sufficiently different from regular repositories that the same workflows do not apply. Getting them to behave as a proper repo required too many workarounds:

Ultimately, this approach was not worthwhile to pursue.

I ended up saving all gists in a “gists” repo under ~/_dev/repos/github.com/maulomelin/gists/ with each gist under its own folder. I simply copy/paste any updates I make to a gist to its corresponding gist under https://gist.github.com/maulomelin - a minor tweak to my workflow I can easily live with because these updates are straight-forward and relatively infrequent.

Lesson learned: GitHub gists are not normal repos; treat GitHub gists as files in a “gists” repo.