Don't checkout master locally

tl;dr: Don’t git checkout master; use topic branches and detached heads.

Topic branches

It’s good to use so-called “topic” or “feature” branches to organize your work into individual features, instead of committing onto what I’ll call “mainline” or “persistent” branches directly. This is a fairly common practice, and I won’t go into full detail on why I think it’s important, but a few good reasons:

Referring to master

Even if we don’t commit directly onto a local master branch, we still often need to refer to the remote master branch to do things like:

So if we don’t checkout master locally, how do we these things? Easy – git already allows you to refer to remote branches directly, via remote tracking branches, like origin/master.

There’s no reason to have a local master branch to do any of these things.

Detached head

Sometimes we need more direct access to the content at master. E.g., maybe we want to just do a build at master, without necessarily starting a new topic branch.

We can do this using detached heads. In addition to checking out branches, git lets you check out arbitrary commits. So you can just checkout a remote tracking branch directly, with git checkout origin/master.

Why not just checkout master?

Because it’s simpler not to:


 ·  January 22, 2019