Skip to content

Git

The version control system everything else on this page is a front end for.

Homebrew formula

What it does

Git tracks content as a directed graph of commits, each a full snapshot addressed by hash. Branching is cheap, history is rewritable before it is shared, and every clone is a complete repository.

Why install it from Homebrew

macOS ships a Git that comes from the Xcode Command Line Tools — usually a year or more behind, and it disappears or reverts across Xcode updates. The Homebrew build is current and stays where you put it.

git --version
which -a git    # /opt/homebrew/bin/git should win

Two identities on one machine

Working under more than one GitHub account is where Git quietly does the wrong thing. Two settings fix it:

  • git config user.name and user.email set per repository, so commits are attributed correctly without a global default fighting them.
  • An SSH host alias in ~/.ssh/config per account, with the remote written against the alias (git@github-work:org/repo.git) so the right key is offered.

Rewriting such a remote back to git@github.com: silently selects the default key and the push fails, or worse, succeeds as the wrong user.

Alternative to

AlternativeTypeTrade-off
Jujutsu (jj)Open sourceGit-compatible storage with a much better model for rewriting history
MercurialOpen sourceSimpler and more consistent; still used at scale inside a few large companies
FossilOpen sourceVersion control, bug tracker and wiki in one file
Perforce or SubversionPaid / Open sourceCentralised, and still standard in games and some enterprises

Install

brew install git

Links

This post is licensed under CC BY 4.0 by the author.
Last updated on