Install or upgrade Git for MAC

Homebrew macOS

Homebrew macOS (or Linux) missing package manager brex.sh /index_zh-cn

Homebrew is a package manager. It installs the package into its own directory and symlinks its files to /usr/local

brew list
brew info git
Copy the code

1. The MAC system xcode contains Git

Git comes with Xcode by default

2. install git

brew install git
==> Installing dependencies forgit: gettext and pcre2 ==> Installing git dependency: The gettext = = > Downloading https://homebrew.bintray.com/bottles/gettext-0.20.1.mojave.bottle.tar.gz = = > Downloading the from https://akamai.bintray.com/fa/fa2096f80238b8f4d9f3724d526626ab4db5c0586f3746ee13fc66e5a625aa1a?__gda__=exp=1569381062~hm ac=c97e42a3c09abe96b2618b9bacc0241dc4010e5f# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # (100.0%)= = > Pouring gettext - 0.20.1. The mojave. Bottle. Tar. Gz = = > Caveats gettext is keg - only,which means it was not symlinked into /usr/local,
because macOS provides the BSD gettext library & some software gets confused if both are in the library path.

If you need to have gettext first in your PATH run:
  echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profile

For compilers to find gettext you may need to set:
  export LDFLAGS="-L/usr/local/opt/gettext/lib"
  export CPPFLAGS="-I/usr/local/opt/gettext/include"= = > the Summary 🍺 / usr /local/Cellar/gettext/ 0.20.1:1,899 files, 18.5MB ==> Installing Git Dependency: Pcre2 = = > Downloading https://homebrew.bintray.com/bottles/pcre2-10.33.mojave.bottle.tar.gz = = > Downloading the from https://akamai.bintray.com/fb/fb30c3eebba4483a10378bc8df52f96761fed4a1ac5572ad1bf4afbf2f8638c5?__gda__=exp=1569381077~hm ac=50519d19a5c126346692b191fed2c0e8b59735a3# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # (100.0%)= = > Pouring pcre2-10.33. The mojave. Bottle. Tar. Gz 🍺 / usr /local/ Cellar/pcre2/10.33: 226 files, 5.7 MB = = > Installing git = = > Downloading https://homebrew.bintray.com/bottles/git-2.23.0_1.mojave.bottle.tar.gz = = > Downloading from https://akamai.bintray.com/84/846c80d096bd49662e34de8144e73b2df017a3acb35a15942429e111951ba343?__gda__=exp=1569381086~hm ac=c623daa34fccf94571ada2b614b55954a5a2e327# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # (100.0%)==> Pouring git-2.23.0_1.mojave.bottle. Tar. gz ==> Caveats Bash completion has been installed to: /usr/local/etc/bash_completion.d

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.23.0_1: 1,543 files, 44.9MB
==> Caveats
==> gettext
gettext is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD gettext library & some software gets confused if both are in the library path.

If you need to have gettext first in your PATH run:
  echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profile

For compilers to find gettext you may need to set:
  export LDFLAGS="-L/usr/local/opt/gettext/lib"
  export CPPFLAGS="-I/usr/local/opt/gettext/include"

==> git
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

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
Copy the code

3. Check the Git version

If you are pointing to xcode’s native Git, change the default git pointing

Honglei:~ honglei$ whichGit /usr/bin/git Honglei:~ Honglei $git --version git version 2.20.1 (Apple git-117)Copy the code

Brew link to Git

Next we point Git to the Git we installed through Homebrew via brew Link

Honglei:~ honglei$ brew link git --overwrite
Warning: Already linked: /usr/local/Cellar/git/2.23.0 To relink: brew unlink git && brew link gitCopy the code

5. Verify the Link method

Link is successful, exit the terminal, and open it again. Then check git pointing and version information.

Honglei:~ honglei$ which git
/usr/local/bin/git
git --version
git version 2.20.1 (Apple Git-117)
Copy the code

6. The configuration path

Configure git’s path to git.

PATH="${MAVEN_HOME}/bin:${JAVA_HOME}:${PATH}:/usr/local/bin/git"
Copy the code

Update the git

To view

~ brew info git git: stable 2.29.2, HEAD Distributed Revision Control system https://git-scm.com...Copy the code

update

brew upgrade git
Copy the code

The update process is as follows

brew upgrade git
Updating Homebrew...
Warning: You are using macOS 11.1.
We do not provide support for this pre-release version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Twitter or any other official channels. You are responsible for resolving
any issues you experience while you are running this
pre-release version.

==> Upgrading 1 outdated package:
git 2.23.0_1 -> 2.29.2
==> Upgrading git 2.23.0_1 -> 2.29.2
==> Downloading https://ftp.gnu.org/gnu/gettext/gettext-0.21.tar.xz
Already downloaded: /Users/honglei/Library/Caches/Homebrew/downloads/fbd8967fd8256b2e1856b74e8ff0f3d8371cb652c5768e47649613a69d4dc841--gettext-0.21.tar.xz
==> Downloading https://ftp.pcre.org/pub/pcre/pcre2-10.35.tar.bz2
Already downloaded: /Users/honglei/Library/Caches/Homebrew/downloads/48997c77a7dae2fb85d52234e92e9032019609e091e23d72529d1e552978a260--pcre2-10.35.tar.bz2
==> Downloading https://mirrors.edge.kernel.org/pub/software/scm/git/git-htmldocs-2.29.2.tar.xz
Already downloaded: /Users/honglei/Library/Caches/Homebrew/downloads/121a858acf277913dc50e88327bdab2d23472eaef1be3d6d578e0d2af1581398--git-htmldocs-2.29.2.tar.xz
==> Downloading https://mirrors.edge.kernel.org/pub/software/scm/git/git-manpages-2.29.2.tar.xz
Already downloaded: /Users/honglei/Library/Caches/Homebrew/downloads/943040db2aac5a66a4faae1cb07ea9ea9a98ee2c2928750d2f86277a1b64099b--git-manpages-2.29.2.tar.xz
==> Downloading https://cpan.metacpan.org/authors/id/R/RJ/RJBS/Net-SMTP-SSL-1.04.tar.gz
Already downloaded: /Users/honglei/Library/Caches/Homebrew/downloads/0726c68dac390b617cefcc880f076b50795463c1fba286d46a53082ebed2bc9d--Net-SMTP-SSL-1.04.tar.gz
==> Downloading https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.29.2.tar.xz
Already downloaded: /Users/honglei/Library/Caches/Homebrew/downloads/6b8b369d6a5b8c38330cef909d4a876403d2badc5ab22b2118a562520da30d7c--git-2.29.2.tar.xz
==> Installing dependencies for git: gettext and pcre2
==> Installing git dependency: gettext
==> ./configure --prefix=/usr/local/Cellar/gettext/0.21 --with-included-gettext gl_cv_func_ftello_works=yes --with-included-glib --with-included-libcroco --with-included-libunistring --with-emacs --wi
==> make
==> make install
🍺  /usr/local/Cellar/gettext/0.21: 1,953 files, 19.8MB, built in 9 minutes 52 seconds
==> Installing git dependency: pcre2
==> ./configure --prefix=/usr/local/Cellar/pcre2/10.35 --enable-pcre2-16 --enable-pcre2-32 --enable-pcre2grep-libz --enable-pcre2grep-libbz2 --enable-jit
==> make
==> make install
🍺  /usr/local/Cellar/pcre2/10.35: 230 files, 6.1MB, built in 53 seconds
==> Installing git
==> make install prefix=/usr/local/Cellar/git/2.29.2 sysconfdir=/usr/local/etc CC=clang CFLAGS= LDFLAGS= NO_TCLTK=1 NO_OPENSSL=1 APPLE_COMMON_CRYPTO=1
==> make CC=clang CFLAGS= LDFLAGS=
==> make clean
==> make
==> make test
==> make CC=clang CFLAGS= LDFLAGS=
==> Caveats
The Tcl/Tk GUIs (e.g. gitk, git-gui) are now in the `git-gui` formula.

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

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.29.2: 1,479 files, 39.7MB, built in 1 minute 10 seconds
Removing: /usr/local/Cellar/git/2.23.0_1... (1,543 files, 44.9MB)
==> Upgrading 2 dependents:
libidn2 2.2.0_1 -> 2.3.0, wget 1.20.3_1 -> 1.20.3_2
==> Upgrading libidn2 2.2.0_1 -> 2.3.0
==> Downloading https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz
######################################################################## 100.0%
==> Downloading https://ftp.gnu.org/gnu/libidn/libidn2-2.3.0.tar.gz
######################################################################## 100.0%
==> Installing dependencies for libidn2: pkg-config
==> Installing libidn2 dependency: pkg-config
==> ./configure --prefix=/usr/local/Cellar/pkg-config/0.29.2_3 --disable-host-tool --with-internal-glib --with-pc-path=/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/pkgconfig:/usr/local
==> make
==> make install
🍺  /usr/local/Cellar/pkg-config/0.29.2_3: 11 files, 656.6KB, built in 1 minute 37 seconds
==> Installing libidn2
==> ./configure --prefix=/usr/local/Cellar/libidn2/2.3.0 --with-libintl-prefix=/usr/local/opt/gettext --with-packager=Homebrew
==> make install
🍺  /usr/local/Cellar/libidn2/2.3.0: 72 files, 808.2KB, built in 56 seconds
Removing: /usr/local/Cellar/libidn2/2.2.0_1... (70 files, 700.9KB)
==> Upgrading wget 1.20.3_1 -> 1.20.3_2
==> Downloading https://www.openssl.org/source/openssl-1.1.1h.tar.gz
######################################################################## 100.0%
==> Downloading https://ftp.gnu.org/gnu/wget/wget-1.20.3.tar.gz
######################################################################## 100.0%
==> Installing dependencies for wget: [email protected]
==> Installing wget dependency: [email protected]
==> perl ./Configure --prefix=/usr/local/Cellar/[email protected]/1.1.1h --openssldir=/usr/local/etc/[email protected] no-ssl3 no-ssl3-method no-zlib darwin64-x86_64-cc enable-ec_nistp_64_gcc_128
==> make
==> make test
==> make install MANDIR=/usr/local/Cellar/[email protected]/1.1.1h/share/man MANSUFFIX=ssl
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/[email protected]/certs

and run
  /usr/local/opt/[email protected]/bin/c_rehash

[email protected] is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have [email protected] first in your PATH run:
  echo 'export PATH="/ usr/local/opt/[email protected] / bin:$PATH"'>> ~/. ZSHRC For compilers to find [email protected] you may need to set: Export LDFLAGS=" -l /usr/local/opt/[email protected]/lib" export CPPFLAGS=" -i /usr/local/opt/[email protected]/include" For pkg-config To find [email protected] you may need to set: Export PKG_CONFIG_PATH = "/ usr/local/opt/[email protected] / lib/pkgconfig" = = > the Summary 🍺 / usr/local/Cellar/[email protected]/1.1.1 h: 8060 files, 18.4 MB, Built in 8 minutes 50 seconds = = > Installing wget = = > the. / configure -- prefix = / usr/local/Cellar/wget 1.20.3 _2 - sysconfdir = / usr/local/etc - with - SSL = openssl - with libssl -- prefix = / usr/local/opt/[email protected] Gl_cv_func_ftello_works = yes, disable - pcre, dis = = > make install 🍺 / usr/local/Cellar/wget 1.20.3 _2: 49 files, 4.0 MB, built in 2 minutes 17 seconds o: / usr/local/Cellar/wget 1.20.3 _1... (50 files, 4.0MB) ==> Checking for dependents of Upgraded-formulae... ==> No broken dependents found! ==> Caveats ==> git The Tcl/Tk GUIs (e.g. gitk, git-gui) are now in the `git-gui` formula. Bash completion has been installed to: /usr/local/etc/bash_completion.d 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 - the lisp/git = = > [email protected] A CA file has had been bootstrapped using certificates from the system keychain. To add additional certificates, Place. Pem files in /usr/local/etc/[email protected]/certs and run /usr/local/opt/[email protected]/bin/c_rehash [email protected] is keg-only, which means it was not symlinked into /usr/local, Because macOS provides LibreSSL. If you need to have [email protected] first in your PATH run: echo 'export PATH="/ usr/local/opt/[email protected] / bin:$PATH"'>> ~/. ZSHRC For compilers to find [email protected] you may need to set: Export LDFLAGS=" -l /usr/local/opt/[email protected]/lib" export CPPFLAGS=" -i /usr/local/opt/[email protected]/include" For pkg-config To find [email protected] you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"Copy the code
➜ git version
git version 2.29.2
Copy the code