Install older removed brew formula version While brew has an accessible simple versioning mechanism, it's restricted to versions used by a large number of people. So for popular versions, it's easy:

brew search node # gives node@6, node@8, node@10
brew search postgresql #gives postgresql@9.4, postgresql@9.5, postgresql@9.6, postgresql@10
brew search python # gives python@2


And I can install one for instance with brew install python@2.

But for less popular versions which got removed, let's say git@2.20.1, then it's not obvious how to install them:


  $ brew install git@2.20.1
  Error: No available formula with the name "git@2.20.1"
  ==> Searching for a previously deleted formula (in the last month)...
  Error: No previously deleted formula found.
  ==> Searching for similarly named formulae...
  Error: No similarly named formulae found.
  ==> Searching taps...
  ==> Searching taps on GitHub...
  Error: No formulae found in taps.
Solution based on Versions.html doc
To install a removed brew formula version, we can follow the suggestion from https://docs.brew.sh/Versions.html:

We create an empty repo on our GitHub account: https://github.com/Coeur/homebrew-repo
We add an empty commit to it (git commit --allow-empty -m &quot;first commit&quot;), otherwise brew may not find HEAD.
We extract the old formula with brew extract git Coeur/repo --version=2.20.1
We install this old formula with brew install coeur/repo/git@2.20.1

(note: uninstall command will be brew uninstall git@2.20.1)
More doc at https://docs.brew.sh/How-to-Create-and-Maintain-a-Tap

Solution based on manual search

Find the repository of the formula with brew info git. It should tell us it's https://github.com/Homebrew/homebrew-core/blob/master/Formula/git.rb
From that page, click the History button on the right to get to https://github.com/Homebrew/homebrew-core/commits/master/Formula/git.rb
Choose a commit diff with your relevant version, for instance https://github.com/Homebrew/homebrew-core/commit/67903b677219559ac72b3fb45932d43426e157f0#diff-3e84bae646d908b93e043833873d316d for 2.20.1
Click View file to get to the full file at this version: https://github.com/Homebrew/homebrew-core/blob/67903b677219559ac72b3fb45932d43426e157f0/Formula/git.rb
Click Raw to get to the raw file at this version: https://raw.githubusercontent.com/Homebrew/homebrew-core/67903b677219559ac72b3fb45932d43426e157f0/Formula/git.rb
We install this formula with brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/67903b677219559ac72b3fb45932d43426e157f0/Formula/git.rb

(note: uninstall command will be brew uninstall git)