How to upgrade Git to latest version on macOS?

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

    the simplest way I found so far is from git official website. It just computed dependencies and downloaded all of the required libraries/tools

    http://git-scm.com/book/en/Getting-Started-Installing-Git

    The other major way is to install Git via MacPorts (http://www.macports.org). If you have MacPorts installed, install Git via

    $ sudo port install git-core +svn +doc +bash_completion +gitweb

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

    After searching for "trouble upgrading git on mac" on Google, I read several posts and attempted the following before resolving the problem by completing step 4:

    1. I updated my terminal path by using the above mention export command. Every time I quit the terminal and restarted it, when I typed git --version the terminal, it still return the older version 1.8.

    2. I followed the README.txt instructions for upgrading to the current version 2.0.1 that comes with the .dmg installer and when I restarted the terminal, still no go.

    3. I looked for /etc/path/ folder as instructed above and the directory called "path" does not exist on my Mac. I am running OS X Mavericks version 10.9.4.

    4. Then I recalled I have Homebrew installed on my Mac and ran the following:

      brew --version
      brew update
      brew search git
      brew install git
      

    This finally resolved my problem. If anyone has some insight as to why this worked, further insight would be greatly appreciated. I probably have some left over path settings on my system from working with Ruby last year.

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

    It's simple if you already have Homebrew: Assuming you have homebrew installed, type the following:

    brew install git
    

    This should automatically install git and set it in your path, replacing the Apple one. Quit and restart terminal. Check git version to confirm.

    git --version
    

    If the output of the above command shows the latest version and does not mention Apple with the version details, then you are all set.

    If however you still see apple version, then type the following two lines, which will manually set our path to the local git distro instead of the Apple one.

    export PATH=/usr/local/bin:$PATH
    git --version
    

    IF YOU DON'T HAVE HOMEBREW, FOLLOW THESE STEPS

    Check version

    $ git --version

    Backup (or remove) Apple git (Optional)

    $ sudo mv /usr/bin/git /usr/bin/git-apple

    Install Homebrew if you didn’t have

    $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

    Or update if you already have

    $ brew update && brew upgrade

    Install Git with Homebrew

    $ brew install git

    Symbolic link

    $ brew link --force git

    Quit terminal and open a new terminal, then check version.

    $ git --version

    You should see…

    git version <latest version>

    Nice! We’re safe now! And next time you can just…

    $ brew update && brew upgrade

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

    if using homebrew you can update sim links using

    brew link --overwrite git
    
    0 讨论(0)
  • 2020-12-02 04:52

    I recently upgraded the Git on my OS X machine to the latest also. I didn't use the same .dmg you used, but when I installed it the binaries were placed in /usr/local/bin. Now, the way my PATH was arranged, the directory /usr/bin appears before /usr/local/bin. So what I did was:

    cd /usr/bin
    mkdir git.ORIG
    mv git* git.ORIG/
    

    This moves the several original programs named git* to a new subdirectory that keeps them out of the way. After that, which git shows that the one in /usr/local/bin is found.

    Modify the above procedure as necessary to fit wherever you installed the new binaries.

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

    Without Homebrew

    1. Use the installer from git's website.
    2. Update your ~/.bash_profile file. Notice this command differs from kmikael's answer by what it puts in the file:
      • Other command: export PATH=/usr/local/git/bin:/usr/local/sbin/:[and so on]
      • Below command: export PATH="/usr/local/git/bin:/usr/local/sbin:$PATH"
      • Use whichever one you prefer.

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

    1. If you're using Xcode, you'll need to add some symbolic links.
      • Example: ln -s /opt/local/bin/git /usr/bin/git
    2. Restart terminal.
      • which git should say the directory in the README.txt file from the dmg.
      • git --version should say the updated version.
      • echo $PATH should start with /usr/local/git/bin:/usr/local/sbin:
    0 讨论(0)
提交回复
热议问题