Semantic Version Branches for Submodules
When you create a new git repo, you get a master branch for free. That's fine in many cases.
Lately I've been using a different branching system for code that's meant to be used as a library (perchance a git submodule or a subtree).
Here's how it works:
Name the branch based on the code's Semantic Version. Examples:
Brand-new code base that's still being written: name the branch semver-0.x.
The x in the branch name denotes a variable, so this branch could house v0.0, v0.1, v0.1.42 and so forth.
You probably could get away with a simple v0.x or even 0.x, but I think the explicitness is helpful indicator for humans and paves the way for machine recognition of semantic branch names.
First version of the code base with a stable public API: semver-1.x.
Upcoming not-yet-stable second version of code base: semver-2.x-beta
Initially I went with semver-2.x-unstable, but I found myself confused when I came back to the project later. Does that mean the code is unstable and crashy? Or just the API is subject to change? Both?
Whereas with beta it was instantly clear to me this branch holds the work-in-progress for version 2.
Second version of the code base with a stable public API: semver-2.x.
There's no master branch.
"master" is too generic a concept and it's an attractive nuisance for submodules. Too often I look at a project, see lots of branches and no way to immediately tell what's going on, so I reach for the familiar: the master branch.
Learning from my own behavior, I see it's important to take away that crutch and force perspective library consumers to understand the project's current state and semver branch structure. Fortunately GitHub makes it easy to select a non-master default branch, so it should be mostly transparent to your users.
Even better, switching the default branch gives the library's author the ability to easy start migrating new users to newer versions of your library (while retaining backwards compatibility with your existing users). For example, update your default branch from semver-1.x to semver-2.x.
It's best if you start off immediately using semver branching, but it's straightforward to migrate to them even after you publicly release your library using the old fuddy-duddy master branch model. In that case you'll have to weigh the conceptual clarity and usability advantages of deleting the master branch against breaking the assumed-master branch of your clients.







