How to upgrade Git to latest version on macOS?

前端 未结 15 1809
离开以前
离开以前 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:31

    It would probably be better if you added:

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

    to a file named .bashrc in your home folder. This way any other software that you might install in /usr/local/git/bin will also be found first.

    For an easy way to do this just type:

    echo "export PATH=/usr/local/git/bin:/usr/local/sbin:$PATH" >> ~/.bashrc
    

    into the Terminal and it will do it for you.

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

    I used the following to upgrade git on mac.

    hansi$ brew install git 
    
    hansi$ git --version 
    git version 2.19.0
    
    
    hansi$ brew install git
    Warning: git 2.25.1 is already installed, it's just not linked
    You can use `brew link git` to link this version.
    
    hansi$ brew link git 
    Linking /usr/local/Cellar/git/2.25.1... 
    Error: Could not symlink bin/git
    Target /usr/local/bin/git
    already exists. You may want to remove it:
      rm '/usr/local/bin/git'
    
    To force the link and overwrite all conflicting files:
      brew link --overwrite git
    
    To list all files that would be deleted:
      brew link --overwrite --dry-run git
    
    hansi$ brew link --overwrite git 
    Linking /usr/local/Cellar/git/2.25.1... 205 symlinks created
    
    
    hansi$ git --version
    git version 2.25.1
    
    0 讨论(0)
  • 2020-12-02 04:32

    The latest version was not available as a binary for mac on git-scm.com, so I installed from source. I was missing a required package for localization, and added NO_GETTEXT=true to install without localization.

    git clone https://github.com/git/git.git
    cd git
    make NO_GETTEXT=true
    make NO_GETTEXT=true install
    

    This installed git under ~/bin which I then had to add to the beginning of my PATH variable.

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

    The installer from the git homepage installs into /usr/local/git by default. However, if you install XCode4, it will install a git version in /usr/bin. To ensure you can easily upgrade from the website and use the latest git version, edit either your profile information to place /usr/local/git/bin before /usr/bin in the $PATH or edit /etc/paths and insert /usr/local/git/bin as the first entry.

    It may help to someone at-least changing the order in /etc/paths worked for me.

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

    I did it in this way:

    1. Open GitHub application installed on Mac
    2. Click on Advanced tab → Install command line tools
    3. Once you get a message that all commands have been installed close your terminal and reopen it.
    4. Now check git --version, it should give you the latest version.
    0 讨论(0)
  • 2020-12-02 04:34

    I prefer not to alter the path hierarchy, but instead deal with git specifically...knowing that I'm never going to use old git to do what new git will now manage. This is a brute force solution.

    NOTE: I installed XCode on Yosemite (10.10.2) clean first.

    I then installed from the binary available on git-scm.com.

    $ which git
    /usr/bin/git
    $ cd /usr/bin
    $ sudo ln -sf /usr/local/git/bin/git
    $ sudo ln -sf /usr/local/git/bin/git-credential-osxkeychain
    $ sudo ln -sf /usr/local/git/bin/git-cvsserver
    $ sudo ln -sf /usr/local/git/bin/git-receive-pack
    $ sudo ln -sf /usr/local/git/bin/git-shell
    $ sudo ln -sf /usr/local/git/bin/git-upload-archive
    $ sudo ln -sf /usr/local/git/bin/git-upload-pack
    $ ls -la
    (you should see your new symlinks)
    
    0 讨论(0)
提交回复
热议问题