GitのバージョンアップデートとPATHの追加（Mac）

#はじめに

Gitのバージョンが古いのでアップデートすることにしました。

```
% git --version
git version 2.24.3 (Apple Git-128)
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/391107/c03e4bb6-927d-475e-36c9-712807f1dab4.png)


#環境

- MacBookPro
- Catalina

#アップデート

インストールコマンドを実行するとアップデートされます。
こんな風にHomebrewも一緒にアップデートされます。

```
% brew install git
Updating Homebrew...
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
as-tree                    libunwind                  pyqt-builder
glibc                      lttng-ust                  pyqt-networkauth
haskell-language-server    numactl                    pyqt@5
iconsur                    pyqt-3d                    threemux
==> Updated Formulae
Updated 296 formulae.

==> Downloading https://homebrew.bintray.com/bottles/gettext-0.21.catalina.bottl
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/cdea54f52b7c36ebcb5fe
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/pcre2-10.36.catalina.bottle
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/d14484c7e5d4a74112474
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/git-2.31.0.catalina.bottle.
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/4070268c3d4b22a48a35b
######################################################################## 100.0%
==> Installing dependencies for git: gettext and pcre2
==> Installing git dependency: gettext
==> Pouring gettext-0.21.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/gettext/0.21: 1,953 files, 19.0MB
==> Installing git dependency: pcre2
==> Pouring pcre2-10.36.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/pcre2/10.36: 230 files, 6.2MB
==> Installing git
==> Pouring git-2.31.0.catalina.bottle.tar.gz
==> Caveats
The Tcl/Tk GUIs (e.g. gitk, git-gui) are now in the `git-gui` formula.

zsh completions and functions have been installed to:
  /usr/local/share/zsh/site-functions

Emacs Lisp files have been installed to:
  /usr/local/share/emacs/site-lisp/git
==> Summary
🍺  /usr/local/Cellar/git/2.31.0: 1,506 files, 41MB
==> Caveats
==> git
The Tcl/Tk GUIs (e.g. gitk, git-gui) are now in the `git-gui` formula.

zsh completions and functions have been installed to:
  /usr/local/share/zsh/site-functions

Emacs Lisp files have been installed to:
  /usr/local/share/emacs/site-lisp/git
```

#アップデートの確認

確認すると・・・古いまま？？

```
% git --version   
git version 2.24.3 (Apple Git-128)
```

#もう一度インストールしてみる

もうインストール済みだよってなる。

```
% brew install git
Warning: git 2.31.0 is already installed and up-to-date.
To reinstall 2.31.0, run:
  brew reinstall git
```

実はHomebrewでGitでインストールするとインストール先が下記になります。

```
==> Summary
🍺  /usr/local/Cellar/git/2.31.0: 1,506 files, 41MB
```

#PATHを通す

.zshrc に以下のように追記します。

```
export PATH=/usr/local/Cellar/git/2.31.0/bin:$PATH
```

設定を反映する。

```
% source .zshrc
```

#改めてバージョンを確認する

```
% git --version
git version 2.31.0

% which git 
/usr/local/Cellar/git/2.31.0/bin/git
```