What do the colors mean in the output of `git branch -a`?

Viewed 1482

Four of the branches listed by $ git branch -a for a Git repository are colored in red in the terminal output.

The Git configuration guide has a section headed "Colors in Git" that doesn't explain what the "colors in git" mean, or provide a way to learn what they mean.

Web searches and searching Stack Overflow give no relevant results.

What do the colors in the terminal output of git branch -a mean?

1 Answers

The colors are configurable—both whether they are used at all, and if so, which color has what meaning. The default settings are:

  • Use color if git branch output is going to a "terminal device". That should make you ask the obvious question, What the bleep is a terminal device? The obvious answer from the English language would be a device that kills you, but that's not it. At least, we hope that's not it!

    In this case a "terminal device" is one for which isatty, in the C library, returns a truthful status. That's still rather cryptic, but to go any further, we would have to know what OS and/or C library you are using. On Linux-like systems, including macOS, these days, it mostly means "in a terminal window": something running Terminal or iTerm or xterm or one of the many other things that, indirectly, emulate an ancient printer from the late 1960s. More precisely, they're emulating something emulating the VT100, which emulated the ADM3A, which—as a so-called "glass tty"—emulated the ASR33 and other similar printers.

  • Use green for the current branch; use red for any remote-tracking names;1 and use the default—whatever that is for your terminal emulator—for all remaining names.

This helps distinguish the current branch (standing out in green) and remote-tracking names (which, while listed by git branch, aren't really branch names, in an important way). In particular, you cannot get "on" a remote-tracking branch the way you get "on" a (local) branch. The word local in parentheses here is redundant: all branch names are local (see footnote 1 again).


1Git calls these remote-tracking branch names, using the word branch yet again in a way that just makes everything even more confusing. A remote-tracking name, or remote-tracking branch name if you prefer Git's phrase here, is a name that exists locally because your Git software called up some other Git software, probably on some other machine, perhaps on GitHub for instance, and that other Git software said that they—the other machine with the other repository—have some particular branch name.

Your Git—by which I mean your software, running on your machine using your repository—takes their branch names and modifies them, so that they will be entirely separate from any of your branch names. Your Git then stores the modified names—the remote-tracking names—in your own repository. This lets your Git remember their Git's branch names, and corresponding commit hash IDs.

Related