How Do You Version Control Your Subdomains?

With branches! Specifically, orphan branches1:

$ git init && cd
$ git commit --message "Initial commit" --allow-empty
$ git switch --orphan=api
$ git log
fatal: your current branch 'api' does not have any commits yet

This is useful, for example, if you have a private repository on with many members and don’t want to invite them to (or manage) (or pay for) 8 individual subdomain repositories as well.

I prefer to use the form main-<orphan> for branch names. It keeps important branches grouped together in lists and makes it easy to reference parents in working branch names:

$ git switch --orphan=main-blog
$ git commit --message="Initial commit for" --allow-empty
$ git switch --create=blog/feature/comments
$ git branch --verbose
* blog/feature/comments 5093124 Initial commit for
  main                  6c6c484 Initial commit
  main-blog             5093124 Initial commit for

  1. git switch is relatively new, you can also use git checkout --orphan↩︎