How to upgrade Git to latest version on macOS?

前端 未结 15 1811
离开以前
离开以前 2020-12-02 03:57

I just bought a new Mac with OS X Lion and I checked in the Terminal what version of git is installed by default. I got the answer

git --version
> git ver         


        
相关标签:
15条回答
  • 2020-12-02 04:55

    In order to keep both versions, I just changed the value of PATH environment variable by putting the new version's git path "/usr/local/git/bin/" at the beginning, it forces to use the newest version:

    $ echo $PATH

    /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin/

    $ git --version

    git version 2.4.9 (Apple Git-60)

    original value: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin/

    new value: /usr/local/git/bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin

    $ export PATH=/usr/local/git/bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin

    $ git --version

    git version 2.13.0

    0 讨论(0)
  • 2020-12-02 04:55

    You need to adjust shell path , the path will be set in either .bashrc or .bash_profile in your home directory, more likely .bash_profile.

    So add into the path similar to the below and keep what you already have in the path, each segment is separated by a colon:

    export PATH="/usr/local/bin:/usr/bin/git:/usr/bin:/usr/local/sbin:$PATH"
    
    0 讨论(0)
  • 2020-12-02 04:58

    For me, with Homebrew 1.6.7, the following worked:

    brew upgrade git
    
    0 讨论(0)
提交回复
热议问题